Learn the commands to install .Net Core SDK and Runtime on Ubuntu 20.04 LTS Focal Fossa Linux using the terminal – Apt Repository, Script, or Snap.
Microsoft DotNet is one of the most popular software development frameworks for several years. The .NET Core is a free and open-source platform for building modern cloud-based web applications on Windows, Linux, and macOS operating systems. It is a cross-platform successor to the .NET Framework. The project is mainly developed by Microsoft and published under an MIT license. Compared to the .Net Framework, the .NET Core is more focused on web, Windows Mobile, and Windows applications.
.NET Core is provided as a series of NUGET packages. It was factored, modularized, and delivered as several NUGET packages. Although the common runtime libraries are still part of the bundle, the developer has the freedom to selectively integrate other libraries as required. This makes .NET Core very lightweight. No additional luggage.
- Steps to install .Net Core SDK & Runtime on Ubuntu 20.04 LTS
Steps to install .Net Core SDK & Runtime on Ubuntu 20.04 LTS
#1st Method: Using Script
Download Dotnet Installation Script
Well, one of the easiest possible ways to start with Dotnet is to install it with the script officially provided by Microsoft. The user can use it to install both .Net SDK or Core and .Net Runtime.
sudo apt install wget
Get the Script
Make it executable:
chmod +x dotnet-install.sh
Install .Net Core SDK on Ubuntu 20.04 LTS
.Net Core SDK includes all the tools a developer is required to build and run .NET applications either using a command line or some graphical editor such as Visual Studio. Apart from Visual Studio support it also includes .NET Runtime; ASP.NET Core Runtime and .NET Desktop Runtime 6.0.1. While writing this tutorial the current long term version for open source .Net was 6, hence to get it you can simply type:
./dotnet-install.sh -c Current
The above command will download and install the latest version available via the Microsoft repository. Whereas the user who is looking for some particular one, replace the ‘Current’ in the above command with that.
Whereas the user who is looking for some particular version can replace the ‘Current’ in the command with that. For example, if you want to install version .Net version 5, the above command will be like:
./dotnet-install.sh -c 5.0
Note: The installation path will be “
/home/$USER/.dotnet“. The $USER is the one you used to run the above-given script. Also, you can add this path to your system variable to globally access the dotnet command line.
Note: Replace $USER with your current one:
echo 'export PATH="$PATH:/home/$USER/.dotnet/"' >> ~/.bashrc
If you don’t have its folder in the path then you get “dotnet command not found on your ubuntu”. Otherwise either you have to switch its folder or need to mention its folder path every time to run it.
Install .Net Core RunTime on Ubuntu 20.04
If you don’t want the complete .Net Core SDK to develop applications and only seek for its Runtime environment to run the developed applications and abstract all the interaction with the base operating system; then instead of running the earlier command use the given ones.
ASP.NET Core Runtime allows to run existing web/server applications whereas for only dotnet runtime go for the second command:
./dotnet-install.sh -c Current --runtime aspnetcore
Only for .Net Runtime
./dotnet-install.sh -c Current --runtime dotnet
#2nd method using APT repository- The best one
If you don’t want to use the script to install Dotnet on Ubuntu 20.04 or 18.04 Linux then another method is by adding the repository. This will give us an easy way to update .Net in the future by using the APT command.
Add .Net Repository
As I said if you want to get easily future updates for this Microsoft developing platform then add its repository manually. Here are the commands to follow:
Add the repo:
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
Run Update and also install tool for HTTPS support
sudo apt update sudo apt install -y apt-transport-https
Apt command to install .Net Core SDK on Ubuntu Focal
Finally, we are done with the repository, now it’s time to simply use the APT package manager command for the installation of Microsoft dot net.
sudo apt install dotnet-sdk-6.0
Whereas for only Asp .Net Core runtime use:
sudo apt-get install aspnetcore-runtime-6.0
And for Only .Net Runtime, this one:
sudo apt-get install dotnet-runtime-6.0
Remove or Uninstall SDK (optional)
To remove SDK using APT run:
sudo apt remove dotnet-sdk-6.0
#3rd way: Install using SNAP
Use Snap to install Dotnet on Ubuntu 20.04
Well, if you are interested in SNAP, then here it is. SNAP comes default on Ubuntu as it is available pre-installed.
Next to install the complete .Net SDK using snap go for the given command:
sudo snap install dotnet-sdk --classic --channel=6.0
To access its command line without mentioning the SDK version, set alias:
sudo snap alias dotnet-sdk.dotnet dotnet
To uninstall (optional):
sudo snap remove dotnet-sdk --classic --channel=6.0