How do I install dotnet linux Ubuntu?
Before starting our journey dotnet linux or dotnet core linux . This installation assume clean machine fresh install , that mean you have not tried installing using snap or scripting and you are are not stuck in the middle.
First please check your ubuntu version and verify that it is compatible with .NET Core version you are planning to target by looking into the support table mentioned at start of the article.
!!! Don’t Recommend installing using Snap or Scripting – you can google yourself why !
@ Recommend way to install is using Microsoft Packages.
For This article we will be installing .NET Core 6 on Ubuntu 22.04
The following versions of .NET are ❌ no longer supported on ubuntu 22.04.
.NET 5
.NET Core 3.1
.NET Core 3.0
.NET Core 2.2
.NET Core 2.1
.NET Core 2.0
Check your ubuntu version by using this command
lsb_release -a
Step# 1 First , Check if .NET Core is already installed. Skip to next step if you are sure you don’t have dotnet core for linux on your system.
Open terminal or .NET core CLI and run command mentioned below to find out if we don’t already have .NET core installed on system.
Purpose : Check SDK version
dotnet --list-sdk
OUTPUT should be something similar like below with no errors truncated for readability
2.1.500 [/home/user/dotnet/sdk] 2.1.502 [/home/user/dotnet/sdk] 2.1.504 [/home/user/dotnet/sdk] 2.1.600 [/home/user/dotnet/sdk]
Purpose : Check .NET Core runtime version
dotnet --list-runtimes
Purpose: Check for install folders.
It’s possible that .NET Core 3.1 or other version is installed but not added to the PATH variable for your operating system or user profile.
•dotnet executable
/home/user/share/dotnet/dotnet
•NET SDK
/home/user/share/dotnet/sdk/{version}/
•NET Runtime
/home/user/share/dotnet/shared/{runtime-type}/{version}/
Step# 2 Now Let’s Add the Microsoft package signing key by running the Command specific to your ubuntu version .
- Linux Ubuntu 22.04
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
Now run the following commands below.
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
Step#3 Configure apt preferences, to prioritize PMC repository, by creating the following file: /etc/apt/preferences
Create a file
sudo touch /etc/apt/preferences
Open file using gedit
sudo gedit /etc/apt/preferences
put this contents in file save it
additionaly re-open the file to check if your changes are saved correctly:
Package: *
Pin: origin “packages.microsoft.com”
Pin-Priority: 1001
Step# 4 After that , Install .NET core 6 on Ubuntu 22.04 LTS we have this latest lts version in our case.
sudo apt update
sudo apt install -y dotnet-sdk-6.0
Step#5 Finally , Verify the installation by using the command below
dotnet --info
Step# 6 Create a dotnet test project and run it.
-- Create a sample console app using CLI command below
dotnet new console -o hellowordapplication
Optionally Make a change n Program.CS as listed in the image above. Now let’s run the dotnet core application. you might have to cd into the folder where project was created. Run the command below to run the dotnet core sample project.
dotnet run
you will see helloworld in the output.
Below is the Video Version if you prefer to watch. Please Subscribe youtube channel for updates.
You are all set. Sharing is caring so If it was helpful please comment and share. you can also read about when to choose .net core.
Next
Recommended system requirements:
- 2 GHz dual core processor or better
- 4 GB system memory
- 25 GB of free hard drive space
- Either a DVD drive or a USB port for the installer media
- Internet access is helpful
Ubuntu 22.04 LTS includes the latest OpenStack release, Ussuri, as a preview with final release coming in the 2204.1 LTS,
Please refer to the OpenStack Ussuri release notes for full details of this release of OpenStack.
Hello
I followed the instructions but I already owned a 3.1 version
after I finish when I wirte dotnet –list-sdks
.net 6 did not appear jsut .net 3.1
in the linke you share you did not tell us that we need to delete it
also I don’t want to delete it I need to have the both
[…] If using Linux here is the guide on how to install .net core 6 on ubuntu 22.04 […]
[…] If using Linux here is the guide on how to install .net core 6 on ubuntu 22.04 […]