Ubuntu: Installing .NET SDK 6 on Ubuntu 20.04

The Microsoft .NET SDK is an open-source development platform for developing applications across multiple architectures and operating systems.

In this article, I will show you how to install the .NET SDK on Ubuntu 20.04 and then create/compile/run a simple web application.

Ubuntu 22 will have the dotnet-sdk available in the default Ubuntu apt repositories, but for Ubuntu 20.04 we need to add the Microsoft apt repository and its packaging signing key (per the docs).

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

Then install the apt package:

sudo apt-get update
sudo apt-get install -y dotnet-sdk-6.0

Validate with example .NET web app

As a test, let’s create, compile, and then run a small Hello World web application.

# use the 'web' template to create a .NET project
dotnet new web --name dotnet-hello-web --no-https
cd dotnet-hello-web

# get port that app will use
app_url=$(jq '.profiles.dotnet_hello_web.applicationUrl' Properties/launchSettings.json -r)
echo "Command to test application: 'curl $app_url'"

# run .NET web application
dotnet run

From another console run the curl command, and see the expected response.

$ curl http://localhost:5007
Hello World!

 

REFERENCES

microsoft docs, installing dotnet-sdk-6.0 on Ubuntu 20.04

microsoft docs, installing .NET on Linux

microsoft docs, ‘dotnet new’ command

microsoft docs, dotnet run command

stackoverflow, default port on .NET Docker image

microsoft tutorial, .net web app without https

Jason Watmore, create .net hello world web app

NOTES

installation on Ubuntu 22.04 with apt

sudo apt-cache search dotnet-sdk
sudo apt install dotnet-sdk-6.0 -y