How to Install .NET 8 in Ubuntu 22.04 LTS

Microsoft announced .NET 8 a few days ago. Here’s a step by step guide shows how to install it in Ubuntu 22.04 LTS.

.NET 8 is a new LTS release with 3 years support. It features new code generator “Dynamic Profile-Guided Optimization” (PGO), AVX-512 instruction set, out-of-the-box AI features, first preview of .NET Aspire, native AoT, and various other changes. See the release note for details.

How to Install .NET 8 SDK/Run-time in Ubuntu 22.04

Ubuntu has included the new release package into system repository for Ubuntu 23.10.

Don’t know if it will be backported to Ubuntu 22.04 LTS repository, but here you can install it through Microsoft’s official apt repository.

1. install the key

To add the Microsoft repository, you have to first download & install the key file.

To do so, press Ctrl+Alt+T on keyboard to open terminal. When terminal opens, run single command:

sudo wget -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/keyrings/microsoft.gpg

This command will download the key, dearmor it (so it’s unreadable code, see the screenshot), and save to ‘/etc/apt/keyrings’ directory.

2. Add the Microsoft repository

Next, in terminal window, run command to create & edit the sources file:

sudo gedit /etc/apt/sources.list.d/microsoft.sources

Depends on your desktop environment, replace gedit with mousepad for XFCE, pluma for MATE, or nano that works in most cases.

When the file opens, add following lines and save it.

Types: deb
URIs: https://packages.microsoft.com/ubuntu/22.04/prod/
Suites: jammy
Components: main
Architectures: amd64
Signed-By: /etc/apt/keyrings/microsoft.gpg

For Ubuntu 20.04, replace 22.04 with 20.04, and jammy with focal.

3. Install .NET 8

Finally, update system package cache by running command:

sudo apt update

And, install .NET 8 SDK, runtime:

sudo apt install dotnet-sdk-8.0

I’m not .NET developer, but you can try dotnet --version after installation to verify.

Uninstall .NET 8

To remove .NET 8, open terminal (Ctrl+Alt+T) and run command:

sudo apt remove --autoremove aspnetcore-runtime-8.0 dotnet-sdk-8.0 dotnet-runtime-8.0

And, remove the Microsoft repository by running the 2 commands below to delete sources and key files:

sudo rm /etc/apt/keyrings/microsoft.gpg
sudo rm /etc/apt/sources.list.d/microsoft.sources

Finally, run sudo apt update to refresh cache.