This tutorial shows how to install Microsoft .NET framework, so far .NET 9 STS or .NET 8 LTS, in Debian, Fedora, and their based Linux Distributions.
Microsoft has been maintaining its own Linux repositories for a few years. Which, contains many software packages (including .NET) for modern Linux distributions.
And, here’s how to add the repository and install .NET in Debian 10 / 11 / 12, SUSE Linux 12/15, CentOS 8, Fedora 39, 40, 41, and RHEL 7/8/9.
NOTE: for Ubuntu and Linux Mint, please see this tutorial instead!
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.
First, install the key by running 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's stuck at blinking cursor!
Then, add the repository for Debian 12 via command:
printf 'deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/debian/12/prod bookworm main\n' | sudo tee /etc/apt/sources.list.d/microsoft.list >/dev/null
For Debian 11, use this command instead to add repository:
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
And for Debian 9 / 10, replace the number to 10
and codename to buster
in the command.
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 41 according to system version):
sudo rpm -Uvh https://packages.microsoft.com/config/fedora/41/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 9.0 in commands below with 8.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-9.0 dotnet-runtime-9.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-9.0 dotnet-runtime-9.0
And, SUSE Linux users can run the command below in terminal to install the framework:
sudo zypper install dotnet-sdk-9.0 dotnet-runtime-9.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 9.0 with 8.0 accordingly):
sudo apt remove dotnet-sdk-9.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 since 22.04 LTS. But, it’s not hard for other Linux, since Microsoft maintains Linux repositories for the latest software packages.