instalar-net-6-en-un-ordenador-con-linux-ubuntu

Install .NET 6 on a computer with Linux (Ubuntu)

  • 2 min

.NET is a cross-platform development platform for building applications in C# and other languages.

One of the advantages of modern .NET is that we can run applications on a wide variety of architectures and operating systems, including Linux.

We are going to use .NET on a Debian-based distribution. Personally, I am going to use Linux Mint, but it should work with the main Debian-based Linux distros, such as Ubuntu.

This article was born in the .NET 6 era, but .NET 6 is no longer supported. Use a currently supported version, preferably an LTS such as .NET 10, unless you have a specific reason to install a different version.

Installation with APT

If we don’t want to use the Snap manager, we can also use APT to install .NET. To do this, first we add the Microsoft package signing key to the list of trusted keys and add the package repository by doing,

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
Copied!

Next, we can now use APT to install .NET, by running the following commands,

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-10.0
Copied!
sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y aspnetcore-runtime-10.0
Copied!

Installation via Snap

The easiest way to install dotnet is via the Snap package manager. This comes installed by default on several distros, including Ubuntu. In case your distribution doesn’t have it installed, you can do it simply with,

sudo apt update
sudo apt install snapd
Copied!

With Snap already installed on our machine, installing .NET can be done simply by doing.

sudo snap install dotnet-sdk --classic
Copied!

Check the installation

To check that the installation has been successful, we run the following command,

dotnet --version
Copied!

If everything has been installed correctly, we should see the installed .NET version.

linux-dotnet6-version

From here, we can start developing in .NET on Linux by creating a simple project with dotnet new console and running it with dotnet run.