Installing .NET 6 on Ubuntu 22.04 (Jammy) (original) (raw)
We announced support for .NET 6 on Ubuntu 22.04 with our May 2022 Updates. At that time, the supported installation methods were manual installation via a tarball or a .deb package via packages.microsoft.com (PMC). .NET 6 is now available natively via Jammy feeds, which can cause conflicts with PMC feeds. You need to apply the following guidance to install .NET 6 reliably and correctly on Ubuntu 22.04+.
More information will be shared shortly on .NET 6 being available natively in the jammy-updates feed. In general, we recommend that you use the native packages from this feed since it is much easier and simpler.
You can use one of the following scenarios:
- The first two scenarios assume a clean machine. You want .NET 6 packages and haven't installed them before.
- The second two scenarios assume you're machine is in a mixed-state, that you've installed .NET 6 packages before and don't have the ones you want or are in a bad state.
Related:
Clean machine scenario 1: Use .NET 6 Package via Jammy feed
The easiest approach is to use the .NET 6 package available in Jammy feeds. In this scenario, just install dotnet6 and don't register the PMC feed.
You can do that via the following commands:
sudo apt update && sudo apt -y install dotnet6
You can see this demonstrated with Docker:
$ docker run --rm -it ubuntu:jammy
root@4c9d58f507a3:/# apt update && apt install -y dotnet6
root@444999ffd672:/# dotnet --version
6.0.108
Note: This build of .NET 6 is for the 6.0.1xx band. 6.0.4xx builds are available via PMC. That difference matters most to Windows users. Both builds are supported.
Clean machine scenario 2: Use .NET 6 Package via PMC
You can install .NET 6 on Ubuntu 22.04 from packages.microsoft.com using the following steps:
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
Configure apt preferences, to prioritize PMC repository, by creating the following file: /etc/apt/preferences
To create the file:
sudo touch /etc/apt/preferences
with contents:
Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 1001
Update your APT information:
sudo apt update
Install .NET SDK 6.0:
sudo apt install dotnet-sdk-6.0
Mixed state scenario 1: Use native Jammy packages after installing a previous .NET release from PMC
You may want to switch to using the .NET 6 package available in Jammy after installing .NET 6 from PMC.
Do the following:
- Remove all .NET packages
sudo apt remove --purge dotnet*sudo apt remove --purge aspnetcore*
- Delete PMC repository from APT, using any of the typical methods, for instance by deleting the repo .list file
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
- Update APT
sudo apt update
- Install .NET SDK 6.0
sudo apt install dotnet-sdk-6.0
Mixed state scenario 2: Use PMC packages after installing native Jammy packages
You may want to switch to using packages.microsoft.com packages after installing native packages, potentially because you want to use 6.0.4xx builds.
Do the following:
- Remove all .NET packages
sudo apt remove --purge dotnet*sudo apt remove --purge aspnetcore*
- Create apt preferences file as specified in the section above
- Install .NET SDK 6.0
sudo apt install dotnet-sdk-6.0
How to identify which packages you'd installed
We'll install .NET 6 with both feeds, from a clean state, and then point the various ways you can identify which feed you installed the package from.
First, let's install the native Jammy packages using the "Clean machine scenario 1" guidance.
rich@kamloops:$ docker run --rm -it ubuntu:jammy
root@db7fd8ec177e:/# apt update && apt install -y dotnet6
Get:18 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 dotnet6 amd64 6.0.108-0ubuntu122.04.1 [20.5 kB]
root@db7fd8ec177e:/# dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.108
Commit: 4e3a463d2b
Runtime Environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: ubuntu.22.04-x64 Base Path: /usr/lib/dotnet/dotnet6-6.0.108/sdk/6.0.108/
global.json file: Not found
Host: Version: 6.0.8 Architecture: x64 Commit: 55fb7ef977
.NET SDKs installed: 6.0.108 [/usr/lib/dotnet/dotnet6-6.0.108/sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.NETCore.App]
Download .NET: https://aka.ms/dotnet-download
Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info
Notice that we've installed .NET SDK 6.0.108, installed to /usr/lib/dotnet/, and that the dotnet6 package is being installed from http://archive.ubuntu.com/ubuntu jammy-updates/universe. That's expected for the native packages.
Let's try the same thing with PMC, but with the "Clean machine scenario 2" guidance.
rich@kamloops:~$ docker run --rm -it ubuntu:jammy root@626dcadc888b:/# apt update && apt install -y wget root@626dcadc888b:/# wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb root@626dcadc888b:/# dpkg -i packages-microsoft-prod.deb root@626dcadc888b:/# rm packages-microsoft-prod.deb root@626dcadc888b:/# touch /etc/apt/preferences root@626dcadc888b:/# echo "Package: *" >> /etc/apt/preferences root@626dcadc888b:/# echo "Pin: origin "packages.microsoft.com"" >> /etc/apt/preferences root@626dcadc888b:/# echo Pin-Priority: 1001 >> /etc/apt/preferences root@626dcadc888b:/# cat /etc/apt/preferences Package: * Pin: origin "packages.microsoft.com" Pin-Priority: 1001 root@626dcadc888b:/# apt update && apt -y install dotnet-sdk-6.0 Get:11 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 dotnet-sdk-6.0 amd64 6.0.400-1 [86.4 MB] root@626dcadc888b:/# dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.400 Commit: 7771abd614
Runtime Environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: ubuntu.22.04-x64 Base Path: /usr/share/dotnet/sdk/6.0.400/
global.json file: Not found
Host: Version: 6.0.8 Architecture: x64 Commit: 55fb7ef977
.NET SDKs installed: 6.0.400 [/usr/share/dotnet/sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Download .NET: https://aka.ms/dotnet-download
Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info
Notice that we've installed .NET SDK 6.0.400, installed to /usr/share/dotnet/, and that the dotnet6 package is being installed from https://packages.microsoft.com/ubuntu/22.04/prod jammy/main. That's expected for PMC packages.
We can also tell if the Microsoft PMC feed is registered:
root@626dcadc888b:/# ls /etc/apt/sources.list.d/ microsoft-prod.list root@626dcadc888b:/# cat /etc/apt/sources.list.d/microsoft-prod.list deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/22.04/prod jammy main
If you are using native packages, that file won't and shouldn't be present.