How to Install .NET 9 (or 8) in Ubuntu 24.04 | 22.04 | 20.04

Last updated: November 19, 2024 — Leave a comment

This tutorial shows how to install Microsoft .NET software development framework (9.0, 8.0, or even 6.0, 7.0) in current Ubuntu 24.04, Ubuntu 22.04, and Ubuntu 20.04 LTS.

Microsoft announced .NET 9 last week. It features over 1,000 performance related changes across the runtime, workloads, and languages. .NET Aspire 9 now has OpenAI, Ollama, Milvus integration, and preview support for Azure Functions. For other features and changes, see the announcement.

To install .NET framework in Ubuntu, there are 4 choices:

  • native .deb package from Ubuntu system repository.
  • native .deb package from Microsoft repository.
  • Snap package runs in sandbox.
  • native .deb package from Ubuntu PPA

According what you need, choose one of the options below.

Option 1: Install .NET from Ubuntu system repository

Ubuntu has .NET packages in system repositories. So far, they include:

  • .NET 6 and .NET 7 for Ubuntu 22.04.
  • .NET 8 for Ubuntu 22.04, Ubuntu 24.04, and Ubuntu 24.10.

To install .NET 8 in 22.04 and higher, press Ctrl+Alt+T on keyboard to open terminal and run commands:

sudo apt update
sudo apt install dotnet8

If you want to install .NET 7 in Ubuntu 22.04 only, use command:

sudo apt install dotnet7

And, replace number 7 in command with 6 for .NET 6.

Option 2: Install .NET from Microsoft repository

Microsoft has an official apt repository for Debian/Ubuntu users. It contains:

  • .NET 6, .NET 7, .NET 8 for Ubuntu 20.04 and Ubuntu 22.04.
  • .NET 9 for Ubuntu 20.04 at the moment of writing, though it may add on 22.04/24.04 support soon.

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, 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 gnome-text-editor for Ubuntu 24.04, 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

Here, replace 22.04 and jammy (they are for 22.04 and Mint 21) in the code with:

  • 20.04 and focal for Ubuntu 20.04.
  • 24.04 and noble for Ubuntu 24.04 and Linux Mint 22.

3. Install .NET

Finally, update system package cache by running command:

sudo apt update

And, install .NET 8 SDK, runtime:

sudo apt install dotnet-sdk-8.0

For choice, you may replace dotnet-sdk-8.0 with dotnet-sdk-9.0 for .NET 9 (20.04 only at the moment), or dotnet-sdk-6.0 for .NET 6.

Option 3: Install .NET from Ubuntu PPA

Ubuntu team members also maintain a backport PPA, which so far contains:

  • .NET 6 and .NET 7 for Ubuntu 24.04.
  • .NET 9 for both Ubuntu 22.04 and Ubuntu 24.04.

To add the PPA, open terminal (Ctrl+Alt+T) and run command:

sudo add-apt-repository ppa:dotnet/backports

Type user password when it asks, though there’s no asterisk feedback, and hit Enter to continue.

Then, install .NET 9 by running command:

sudo apt install dotnet9

Or install .NET 6 or 7 (replace number 6 in command accordingly), if you want, in Ubuntu 24.04 via command:

sudo apt install dotnet6

Option 4: Install .NET via Snap package

All current Ubuntu users can also install .NET as Snap package, through it runs in sandbox environment.

Simply launch Ubuntu Software or App Center, then search ‘dotnet’ filter by Snap package and click install. At the moment of writing, only .NET 8 is available.

Uninstall .NET

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

sudo apt remove --autoremove dotnet9* dotnet-host-9.0 dotnet-sdk-9.0 dotnet-runtime-9.0

As well, replace number 9 in the command above, according to which version you installed and want to uninstall.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

No Comments

Be the first to start the conversation.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

*