A personal blog by Anas Mazioudi (@disklosr)

How to install .NET Core SDK on Linux

— 6 min read
My personal .Net Core dev environnement
My personal .Net Core dev environnement

Thanks to .NET Core, the developer experience in Linux based systems has improved a lot. It is now easier than ever before to develop, build and test .Net apps on Linux. What a great time to be alive!

Let's see how we can install needed dependencies to start developing .Net apps on Linux.

.NET Core Linux packages

There are two main packages you might need to install. If you're developing regular .NET Core apps, you need to install .NET Core SDK. If you're building ASP.NET Core web apps, then you need to install the ASP.NET Core SDK.

Microsoft releases official Linux packages for .NET Core runtimes and SDKs which are available for most Linux flavors. These packages follow a nice, hackable naming scheme: {product}-{type}-{version}.

So for example, if you need to install ASP.NET core SDK version 2.1, then you would look for a package named aspnetcore-sdk-2.1. You should be able to install multiple versions of runtimes and SDKs side-by-side without issues. The only minor problem is that these packages aren't included in the official package repositories. Extra steps are needed to get them from Microsoft's proprietary repositories.

Below are examples of instructions for three chosen Linux distros. The examples showcase the installation of ASP.NET Core SDK 3.1, which is the latest SDK version at the time of this writing.

Instructions for Ubuntu

Before installing the needed package, you first need to register Microsoft's key and repository:

#Register Microsoft's key
wget https://packages.microsoft.com/config/ubuntu/19.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

#Update your repo
sudo apt-get update

#This package is needed to be able to get repos behind an HTTPS url
sudo apt-get install apt-transport-https

#Update a second time so you get Microsoft's HTTPS repository
sudo apt-get update

#Install our package
sudo apt-get install dotnet-sdk-3.1

Instructions for CentOS

Similarly to Ubuntu, you need to add Microsoft's repository before installing the desired package:

#Register Microsoft's key
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

#Install our package
sudo yum install dotnet-sdk-3.1

Instructions for Arch Linux

I use Manjaro as my main development OS, which is a distro based on Arch Linux and an excellent choice for doing .NET development. Arch Linux is unfortunately not officially supported by Microsoft so instructions are a bit different here. First, the naming doesn't exactly match the scheme presented above, and second you might need to install both the runtime and SDK as none of them comes included with the other:

#Install runtime as it's not shipped with SDK
sudo pacman -S dotnet-runtime

#Install sdk
sudo pacman -S dotnet-sdk

Keep in mind that this is a community package; it's not released or supported by Microsoft. Also, notice how the package name doesn't include versions. In Arch you'll usually get the latest one, but should you need a specific version, you can use this generic installation script provided by the .NET Foundation. Make sure you check out its documentation here

Verifying your installation:

Once you're done with installation, it's always a good idea to check everything's fine before you start developing. The dotnet command line tool allows you to list all installed .NET Core runtimes and SDKs in your system. Here's how you do it:

#Checking installed runtimes
~> dotnet --list-runtimes
Microsoft.AspNetCore.App 3.1.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

#Checking installed SDKs
~> dotnet --list-sdks
3.1.201 [/usr/share/dotnet/sdk]

What about .NET Core tools?

Starting from .NET Core 2.1, the .NET Core CLI allows installing and using .NET Core tools, which are special NuGet packages containing console applications. They are equivalent to npm tools if you're familiar with them. One widely used .NET Core CLI tool is dotnet-ef, which is used to manage and operate Entity Framework Core.

If you've correctly installed the .NET Core SDK, you should have access to dotnet command line utility, which you can use to install the tools you need. For instance, here's how you install the dotnet-ef tool globally:

~> dotnet tool install --global dotnet-ef

You can invoke the tool using the following command: dotnet-ef
Tool 'dotnet-ef' (version '3.1.3') was successfully installed.

When using a newly installed tool, you might encounter this error:

~> dotnet ef

Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

The tool is complaining about not being able to find the dotnet-ef binary. The fix is rather simple, just include $HOME/.dotnet/tools in your path:

#Add dotnet tools directory to path
~> export PATH="$PATH:$HOME/.dotnet/tools/"

To make the change persistent across terminal sessions and reboots, make sure you include it in your .bashrc or .zshrc files. The dotnet CLI should now be able to find your installed tools:

~> dotnet ef
---==/ \\
___ ___ |. \|\
| __|| __| | ) \\\
| _| | _| \_/ | //|\\
|___||_| / \\\/\\

Entity Framework Core .NET Command-line Tools 3.1.3

Usage: dotnet ef [options] [command]

Now you should have everything needed to develop .NET Core apps in your Linux system!

Happy coding.

Found this post interesting? You can share it on
, , Hackernews, Reddit,
mail it to a friend, or save it to Pocket