Install .NET 5 on Ubuntu 20.04

Install .NET 5 on Ubuntu 20.04

.NET (previously known as .NET Core) is a cross-platform applications development framework created by Microsoft. It is successor to .NET Framework. .NET is an open-source project available under the MIT License. It supports C#, F# and Visual Basic programming language.

.NET Runtime allows to run .NET applications. .NET Software Development Kit (SDK) includes Runtime, debugging and development tools to build and run .NET applications.

This tutorial shows how to install .NET 5 on Ubuntu 20.04.

Install .NET

Download Debian package (.deb) that adds and configures the Microsoft repository:

wget -O packages-microsoft-prod.deb

Install the downloaded package:

sudo dpkg -i packages-microsoft-prod.deb

The .deb package is no longer needed, remove it:

rm -rf packages-microsoft-prod.deb

Run the following command to update the package lists:

sudo apt update

Install .NET 5:

sudo apt install -y dotnet-sdk-5.0

After installation is completed, we can check .NET SDK version currently in use:

dotnet --version

We can also display installed SDKs and runtimes:

dotnet --list-sdks
dotnet --list-runtimes

Testing .NET

Execute the following command to create application project based on console template in the helloworld directory:

dotnet new console -o helloworld -n test

The -n option specifies name for application what will be built.

Go to project directory:

cd helloworld

Remove default Program.cs file and create a new Test.cs file:

rm -rf Program.cs
nano Test.cs

Add the following code:

using System;
public class Test
    public static void Main()
        Console.WriteLine("Hello world");

Build a project using Release configuration in the build directory:

dotnet build -c Release -o build

Now run application:


Uninstall .NET

If you decided to completely remove .NET and all related dependencies, run the following command:

sudo apt purge --autoremove -y dotnet-sdk-5.0 packages-microsoft-prod

We can also remove .NET related directories and files:

rm -rf ~/.dotnet
rm -rf ~/.templateengine
sudo rm -rf /etc/profile.d/

Leave a Comment

Cancel reply

Your email address will not be published.