Install the .NET SDK or the .NET Runtime on Ubuntu
This article describes how to install .NET on Ubuntu. The Microsoft package repository contains every version of .NET that is currently, or was previously, supported on Ubuntu. Starting with Ubuntu 22.04, some versions of .NET are available in the Ubuntu package feed. For more information about available versions, see the Supported distributions section.
Warning
It's recommended that you choose a single repository to source .NET packages. Don't mix .NET packages from multiple package repositories, as this leads to problems when apps try to resolve a specific version of .NET.
Method | Pros | Cons |
---|---|---|
Package manager (Microsoft feed) |
|
|
Package manager (Ubuntu feed) |
|
|
Script \ Manual extraction |
|
|
Decide how to install .NET
When your version of Ubuntu supports .NET through the built-in Ubuntu feed, support for those builds of .NET is provided by Canonical and the builds might be optimized for different workloads. Microsoft provides support for packages in the Microsoft package repository feed.
Use the following sections to determine how you should install .NET:
- I'm using Ubuntu 22.04 or later, and I only need .NET
- I'm using a version of Ubuntu prior to 22.04
- I'm using other Microsoft packages, such as
powershell
,mdatp
, ormssql
- I want to create a .NET app
- I want to run a .NET app in a container, cloud, or continuous-integration scenario
- My Ubuntu distribution doesn't include the .NET version I want, or I need an out-of-support .NET version
- I want to install a preview version
- I don't want to use APT
- I'm using an Arm-based CPU
I'm using Ubuntu 22.04 or later, and I only need .NET
Install .NET through the Ubuntu feed. For more information, see the following pages:
- Install .NET on Ubuntu 22.04.
- Install .NET on Ubuntu 22.10.
- Install .NET on Ubuntu 23.04.
- Install .NET on Ubuntu 23.10.
Important
.NET SDK versions offered by Canonical are always in the .1xx feature band. If you want to use a newer feature band release, use the Microsoft feed to install the SDK. Make sure you review the information in the .NET package mix ups on Linux article to understand the implications of switching between repository feeds.
If you're going to install the Microsoft repository to use other Microsoft packages, such as powershell
, mdatp
, or mssql
, you need to deprioritize the .NET packages provided by the Microsoft repository. For instructions on how to deprioritize the packages, see My Linux distribution provides .NET packages, and I want to use them.
I'm using a version of Ubuntu prior to 22.04
Use the instructions on the version-specific Ubuntu page.
Review the Supported distributions section for more information about what versions of .NET are supported for your version of Ubuntu. If you're installing a version that isn't supported, see Register the Microsoft package repository.
I'm using other Microsoft packages, such as powershell
, mdatp
, or mssql
If your Ubuntu version supports .NET through the built-in Ubuntu feed, you must decide which feed should install .NET. The Supported distributions section provides a table that lists which versions of .NET are available the package feeds.
If you want to source the .NET packages from the Ubuntu feed, you need to deprioritize the .NET packages provided by the Microsoft repository. For instructions on how to deprioritize the packages, see My Linux distribution provides .NET packages, and I want to use them.
I want to create a .NET app
Use the same package sources for the SDK as you use for the runtime. For example, if you're using Ubuntu 22.04 and .NET 6, but not .NET 7, it's recommended that you install .NET through the built-in Ubuntu feed. If, however, you move to .NET 7, which isn't provided by Canonical for Ubuntu 22.04, you should uninstall .NET and reinstall it with the Microsoft package repository. For more information, see Register and install with the Microsoft package repository. Also, review the other suggestions in the Decide how to install .NET section.
I want to run a .NET app in a container, cloud, or continuous-integration scenario
If your Ubuntu version provides the .NET version you require, install it from the built-in feed. Otherwise, register the Microsoft package repository and install .NET from that repository. Review the information in the Supported distributions section.
If the version of .NET you want isn't available, try using the dotnet-install script.
My Ubuntu distribution doesn't include the .NET version I want, or I need an out-of-support .NET version
We recommend you use APT and the Microsoft package repository. For more information, see the Register and install with the Microsoft package repository section.
I want to install a preview version
Use one of the following ways to install .NET:
I don't want to use APT
If you want an automated installation, use the Linux installation script.
If you want full control over the .NET installation experience, download a tarball and manually install .NET. For more information, see Manual install.
I'm using an Arm-based CPU
Use one of the following ways to install .NET:
Supported distributions
The following table is a list of currently supported .NET releases and the versions of Ubuntu they're supported on. Each link goes to the specific Ubuntu version page with specific instructions on how to install .NET for that version of Ubuntu.
Ubuntu | Supported .NET versions | Available in Ubuntu feed | Available in Microsoft feed |
---|---|---|---|
23.10 | 8.0, 7.0, 6.0 | 8.0, 7.0, 6.0 | 8.0, 7.0, 6.0 |
23.04 | 8.0, 7.0, 6.0 | 7.0, 6.0 | 8.0, 7.0, 6.0 |
22.10 | 7.0, 6.0 | 7.0, 6.0 | 7.0, 6.0, 3.1 |
22.04 (LTS) | 8.0, 7.0, 6.0 | 6.0 | 8.0, 7.0, 6.0, 3.1 |
20.04 (LTS) | 8.0, 7.0, 6.0 | None | 8.0, 7.0. 6.0, 5.0, 3.1, 2.1 |
18.04 (LTS) | 7.0, 6.0 | None | 7.0. 6.0, 5.0, 3.1, 2.2, 2.1 |
16.04 (LTS) | 6.0 | None | 6.0, 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 |
When an Ubuntu version falls out of support, .NET is no longer supported with that version.
The following versions of .NET are ❌ no longer supported:
- .NET 5
- .NET Core 3.1
- .NET Core 3.0
- .NET Core 2.2
- .NET Core 2.1
- .NET Core 2.0
Register the Microsoft package repository
The Microsoft package repository contains all versions of .NET that were previously, or are currently, supported with your version of Ubuntu. If your version of Ubuntu provides .NET packages, you'll need to deprioritize the Ubuntu packages and use the Microsoft repository. For instructions on how to deprioritize the packages, see I need a version of .NET that isn't provided by my Linux distribution.
Important
Package manager installs are only supported on the x64 architecture. Other architectures, such as Arm, must install .NET by some other means, such as with the installer script or by manual installation.
Preview releases are not available in the Microsoft package repository. For more information, see Install preview versions.
Caution
We recommend that you only use one repository to manage all of your .NET installs. If you've previously installed .NET with the Ubuntu repository, you must clean the system of .NET packages and configure the APT to ignore the Ubuntu feed. For more information about how to do this, see I need a version of .NET that isn't provided by my Linux distribution.
Installing with APT can be done with a few commands. Before you install .NET, run the following commands to add the Microsoft package signing key to your list of trusted keys and add the package repository.
Open a terminal and run the following commands:
# Get Ubuntu version
declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi)
# Download Microsoft signing key and repository
wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
# Install Microsoft signing key and repository
sudo dpkg -i packages-microsoft-prod.deb
# Clean up
rm packages-microsoft-prod.deb
# Update packages
sudo apt update
Tip
The previous script was written for Ubuntu and it might not work if you're using a derived distribution, such as Linux Mint. It's likely that the $repo_version
variable won't be assigned the correct value, making the URI for the wget
command invalid. This variable maps to the specific Ubuntu version you want to get packages for, such as 22.10 or 23.04.
You can use a web browser and navigate to https://packages.microsoft.com/config/ubuntu/ to see which versions of Ubuntu are available to use as the $repo_version
value.
Install .NET
After you've registered the Microsoft package repository, or if your version of Ubuntu's default feed supports the .NET package, you can install .NET through the package manager with the sudo apt install <package-name>
command. Replace <package-name>
with the name of the .NET package you want to install. For example, to install .NET SDK 8.0, use the command sudo apt install dotnet-sdk-8.0
. The following table lists the currently supported .NET packages:
Product | Type | Package | |
---|---|---|---|
8.0 | ASP.NET Core | Runtime | aspnetcore-runtime-8.0 |
8.0 | .NET | Runtime | dotnet-runtime-8.0 |
8.0 | .NET | SDK | dotnet-sdk-8.0 |
7.0 | ASP.NET Core | Runtime | aspnetcore-runtime-7.0 |
7.0 | .NET | Runtime | dotnet-runtime-7.0 |
7.0 | .NET | SDK | dotnet-sdk-7.0 |
6.0 | ASP.NET Core | Runtime | aspnetcore-runtime-6.0 |
6.0 | .NET | Runtime | dotnet-runtime-6.0 |
6.0 | .NET | SDK | dotnet-sdk-6.0 |
If you want to install an unsupported version of .NET, check the Supported distributions section to see if that version of .NET is available. Then, substitute the version of .NET you want to install. For example, to install ASP.NET Core 2.1, use the package name aspnetcore-runtime-2.1
.
Tip
If you're not creating .NET apps, install the ASP.NET Core runtime as it includes the .NET runtime and also supports ASP.NET Core apps.
Some environment variables affect how .NET is run after it's installed. For more information, see .NET SDK and CLI environment variables.
Uninstall .NET
If you installed .NET through a package manager, uninstall in the same way with the apt-get remove
command:
sudo apt-get remove dotnet-sdk-6.0
For more information, see Uninstall .NET.
Install preview versions
Preview and release candidate versions of .NET aren't available in package repositories. You can install previews and release candidates of .NET in one of the following ways:
Remove preview versions
When using a package manager to manage your installation of .NET, you may run into a conflict if you've previously installed a preview release. The package manager may interpret the non-preview release as an earlier version of .NET. To install the non-preview release, first uninstall the preview versions. For more information about uninstalling .NET, see How to remove the .NET Runtime and SDK.
Use APT to update .NET
If you installed .NET through a package manager, you can upgrade the package with the apt upgrade
command. For example, the following commands upgrade the dotnet-sdk-7.0
package with the latest version:
sudo apt update
sudo apt upgrade dotnet-sdk-7.0
Tip
If you've upgraded your Linux distribution since installing .NET, you may need to reconfigure the Microsoft package repository. Run the installation instructions for your current distribution version to upgrade to the appropriate package repository for .NET updates.
Troubleshooting
Starting with Ubuntu 22.04, you might run into a situation where it seems only a piece of .NET is available. For example, you've installed the runtime and the SDK, but when you run dotnet --info
only the runtime is listed. This situation can be related to using two different package sources. The built-in Ubuntu 22.04 and Ubuntu 22.10 package feeds include some versions of .NET, but not all, and you might have also installed .NET from the Microsoft feeds. For more information about how to fix this problem, see Troubleshoot .NET errors related to missing files on Linux.
APT problems
This section provides information on common errors you might get while using APT to install .NET.
Unable to find package
Important
Package manager installs are only supported on the x64 architecture. Other architectures, such as Arm, must install .NET by some other means such as with Snap, an installer script, or through a manual binary installation.
For more information on installing .NET without a package manager, see one of the following articles:
Unable to locate \ Some packages could not be installed
Note
This information only applies when .NET is installed from the Microsoft package feed.
If you receive an error message similar to Unable to locate package {dotnet-package} or Some packages could not be installed, run the following commands.
There are two placeholders in the following set of commands.
{dotnet-package}
This represents the .NET package you're installing, such asaspnetcore-runtime-8.0
. This is used in the followingsudo apt-get install
command.{os-version}
This represents the distribution version you're on. This is used in thewget
command below. The distribution version is the numerical value, such as20.04
on Ubuntu or10
on Debian.
First, try purging the package list:
sudo dpkg --purge packages-microsoft-prod && sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
Then, try to install .NET again. If that doesn't work, you can run a manual install with the following commands:
sudo apt-get install -y gpg
wget -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget https://packages.microsoft.com/config/ubuntu/{os-version}/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update && \
sudo apt-get install -y {dotnet-package}
Failed to fetch
While installing the .NET package, you may see an error similar to Failed to fetch ... File has unexpected size ... Mirror sync in progress?
. This error could mean that the package feed for .NET is being upgraded with newer package versions, and that you should try again later. During an upgrade, the package feed shouldn't be unavailable for more than 30 minutes. If you continually receive this error for more than 30 minutes, please file an issue at https://github.com/dotnet/core/issues.
Dependencies
When you install with a package manager, these libraries are installed for you. But, if you manually install .NET or you publish a self-contained app, you must install these dependencies to run your app:
- libc6
- libgcc1
- libgcc-s1 (for 22.x)
- libgssapi-krb5-2
- libicu55 (for 16.x)
- libicu60 (for 18.x)
- libicu66 (for 20.x)
- libicu70 (for 22.04)
- libicu71 (for 22.10)
- libicu72 (for 23.04)
- liblttng-ust1 (for 22.x)
- libssl1.0.0 (for 16.x)
- libssl1.1 (for 18.x, 20.x)
- libssl3 (for 22.x)
- libstdc++6
- libunwind8 (for 22.x)
- zlib1g
Dependencies can be installed with the apt install
command. The following snippet demonstrates installing the zlib1g
library:
sudo apt install zlib1g
If the .NET app uses the System.Drawing.Common assembly, libgdiplus will also need to be installed. Because System.Drawing.Common is no longer supported on Linux, this only works on .NET 6 and requires setting the System.Drawing.EnableUnixSupport
runtime configuration switch.
You can install a recent version of libgdiplus by adding the Mono repository to your system.
Next steps
Feedback
Submit and view feedback for