How to Install .NET6 or 7 in Ubuntu 22.04 | 20.04, Debian 11/10 & Other Linux

Ubuntu now support .NET officially. For other Linux, e.g., Debian, SUSE, Fedora, RHEL, this step by step beginner's guide may help!

Good news for Microsoft .NET developers and users! Ubuntu just added official support for .NET 6.0 in the current 22.04 LTS.

It’s the effort of both Microsoft and Canonical (the company behind Ubuntu). The 2 companies has set up a maintainer group for the development platform, to keep updating the packages with security patches and releases.

Meaning Ubuntu users will always have a fresh new .NET LTS in each Ubuntu LTS series.” announced in Ubuntu blog.

To get it, simply open terminal by pressing Ctrl + Alt + T on keyboard, and run commands:

sudo apt install dotnet6
You may first run sudo apt update to refresh cache, in case the command above does not work!

This command will install all the SDK, runtime and ASP.NET packages! To install them separately, user may run either command below in a terminal window:

sudo apt install dotnet-sdk-6.0
sudo apt install dotnet-runtime-6.O
sudo apt install aspnetcore-runtime-6.0

After installation, verify .NET version via dotnet --version and use dotnet --help to print the basic how to use description.

Install .NET 6 or 7 in Linux

Microsoft has been maintaining its own Linux repositories for a few years. There user can get many software packages including .NET framework as easy as a few commands.

And, here’s how to add the repository and install .NET in Ubuntu 18.04, Ubuntu 20.04, Linux Mint 20, Debian 9 / 10 / 11, SUSE Linux 12/15, CentOS 8, Fedora 34/35/36, and RHEL 7/8/9.

Step 1: Add Microsoft Repository

First of all, you need to either open a terminal window or connect to your Linux server command console. Then select run the commands below for your system.

For Debian

Debian has updated its policy for adding third-party repositories. The official guide in Microsoft website is outdated and deprecated.

  • 1. First, run command to download the key, dearmor it, and put it into ‘/usr/share/keyrings‘ directory:

    curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo dd of=/usr/share/keyrings/microsoft.gpg

    Type user password and hit Enter if it stuck at blinking cursor!
  • 2. Then add the repository for Debian 11 via command:

    printf 'deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/debian/11/prod bullseye main\n' | sudo tee /etc/apt/sources.list.d/microsoft.list >/dev/null

For Debian 10, use this command instead to add repository:

printf 'deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/debian/10/prod buster main\n' | sudo tee /etc/apt/sources.list.d/microsoft.list >/dev/null

And for Debian 9, replace the number to 9 and codename to stretch in the command.

For Ubuntu/Linux Mint

Linux Mint 21 and other Ubuntu 22.04 based systems can directly install .NET 6 packages via the apt command.

For old systems, run the commands below one by one to add the software repository.

    • First, run command to get the key and install to the right place:

      curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo dd of=/usr/share/keyrings/microsoft.gpg

      Ubuntu does not has curl out-of-box, install it via 'sudo apt install curl' command.
      And, type user password and hit Enter if it stuck at blinking cursor!
    • Next, add the software repository for Ubuntu 20.04 via command:

      printf 'deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/ubuntu/20.04/prod focal main\n' | sudo tee /etc/apt/sources.list.d/microsoft.list >/dev/null

    • Or use this command instead for Ubuntu 18.04:
      printf 'deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/ubuntu/18.04/prod bionic main\n' | sudo tee /etc/apt/sources.list.d/microsoft.list >/dev/null
    • If you want to install .NET 7 in Ubuntu 22.04, add the repository via command:
      printf 'deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/ubuntu/22.04/prod jammy main\n' | sudo tee /etc/apt/sources.list.d/microsoft.list >/dev/null
Add Microsoft Repository in Ubuntu 20.04

For RHEL/Fedora/SUSE/CentOS

A single command can do the job adding the Microsoft repository in this step. Simply choose the command for your Linux:

  • For RHEL, use the command below with different version number depends on your system:

    sudo rpm -Uvh https://packages.microsoft.com/config/rhel/9/packages-microsoft-prod.rpm

  • And, Fedora user can add the repository via command (also change number 36 accordingly):

    sudo rpm -Uvh https://packages.microsoft.com/config/fedora/36/prod/packages-microsoft-prod.rpm

  • For SUSE Linux, use command (change number 15 according system version):

    sudo rpm -Uvh https://packages.microsoft.com/config/sles/15/packages-microsoft-prod.rpm

  • And CentOS 8 can add the repository via the single command below:

    sudo rpm -Uvh https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm

Step 2: Install .NET SDK/Runtime & ASP.NET

After set up the software repositories, user can now install the framework via command below. Replace 6.0 in commands below with 7.0, depends on which version you want to install.

For Debian/Ubuntu and their derivatives, e.g., Linux Mint, Pop! OS, Zorin OS, use command below to refresh cache & install .NET framework:

sudo apt install dotnet-sdk-6.0 dotnet-runtime-6.0 aspnetcore-runtime-6.0
sudo apt update command is required to update package cache.

Fedora/RHEL/CentOS users can use the command below instead (replace dnf if not work with yum):

sudo dnf install dotnet-sdk-6.0 dotnet-runtime-6.0 aspnetcore-runtime-6.0

And, SUSE Linux users can run the command below in terminal to install the framework:

sudo zypper install dotnet-sdk-6.0 dotnet-runtime-6.0 aspnetcore-runtime-6.0

(Optional) Remove .NET in Linux

In case you want to remove the software packages, use command below in Debian, Ubuntu, Linux Mint (also replace 6.0 with 7.0 accordingly):

sudo apt remove dotnet-sdk-6.0 dotnet-runtime-6.0 aspnetcore-runtime-6.0

For Fedora/CentOS/RHEL, replace apt with dnf or yum in command. Or, use zypper instead for SUSE Linux.

And, to remove the Microsoft repository, simply remove the source file:

  • For Ubuntu/Debian:
    sudo rm /etc/apt/sources.list.d/microsoft.list
  • For Fedora/RHEL/SUSE:
    sudo rm /etc/yum.repos.d/microsoft-prod.repo

Summary

Installing .NET framework is quite easy now in Ubuntu 22.04 LTS. But, it’s not hard for other Linux, since Microsoft maintains Linux repositories for the latest software packages.

Merilyn Ne
Hi, I'm Merilyn Ne, a computer geek working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.