Install .NET Core SDK or .NET Core Runtime on RHEL

.NET Core is supported on RHEL. This article describes how to install .NET Core on RHEL.

Install the SDK (which includes the runtime) if you want to develop .NET apps. Or, if you only need to run apps, install the runtime. If you're installing the runtime, we suggest you install the ASP.NET Core runtime as it includes both .NET Core and ASP.NET Core runtimes.

If you've already installed the SDK or runtime, use the dotnet --list-sdks and dotnet --list-runtimes commands to see which versions are installed. For more information, see How to check that .NET Core is already installed.

Register your Red Hat subscription

To install .NET Core from Red Hat on RHEL, you first need to register using the Red Hat Subscription Manager. If this hasn't been done on your system, or if you're unsure, see the Red Hat Product Documentation for .NET Core.

Supported distributions

The following table is a list of currently supported .NET Core releases on both RHEL 7 and RHEL 8. These versions remain supported until either the version of .NET Core reaches end-of-support or the version of RHEL is no longer supported.

  • A ✔️ indicates that the version of RHEL or .NET Core is still supported.
  • A ❌ indicates that the version of RHEL or .NET Core isn't supported on that RHEL release.
  • When both a version of RHEL and a version of .NET Core have ✔️, that OS and .NET combination are supported.
RHEL .NET Core 2.1 .NET Core 3.1 .NET 5 Preview (manual install only)
✔️ 8 ✔️ 2.1 ✔️ 3.1 ✔️ 5.0 Preview
✔️ 7 ✔️ 2.1 ✔️ 3.1 ✔️ 5.0 Preview

The following versions of .NET Core are no longer supported. The downloads for these still remain published:

  • 3.0
  • 2.2
  • 2.0

How to install other versions

Consult the Red Hat documentation for .NET Core on the steps required to install other releases of .NET Core.

RHEL 8 ✔️

.NET Core is included in the AppStream repositories for RHEL 8.

Install the SDK

.NET Core SDK allows you to develop apps with .NET Core. If you install .NET Core SDK, you don't need to install the corresponding runtime. To install .NET Core SDK, run the following commands:

sudo dnf install dotnet-sdk-3.1

Install the runtime

The .NET Core Runtime allows you to run apps that were made with .NET Core that didn't include the runtime. The commands below install the ASP.NET Core Runtime, which is the most compatible runtime for .NET Core. In your terminal, run the following commands.

sudo dnf install aspnetcore-runtime-3.1

As an alternative to the ASP.NET Core Runtime, you can install the .NET Core Runtime that doesn't include ASP.NET Core support: replace aspnetcore-runtime-3.1 in the command above with dotnet-runtime-3.1.

sudo dnf install dotnet-runtime-3.1

RHEL 7 ✔️

Before you install .NET, run the following commands to add the Microsoft package signing key to your list of trusted keys and add the Microsoft package repository. Open a terminal and run the following commands:

The following command installs the scl-utils package:

sudo yum install scl-utils

Install the SDK

.NET Core SDK allows you to develop apps with .NET Core. If you install .NET Core SDK, you don't need to install the corresponding runtime. To install .NET Core SDK, run the following commands:

subscription-manager repos --enable=rhel-7-server-dotnet-rpms
yum install rh-dotnet31 -y
scl enable rh-dotnet31 bash

Red Hat does not recommend permanently enabling rh-dotnet31 because it may affect other programs. For example, rh-dotnet31 includes a version of libcurl that differs from the base RHEL version. This may lead to issues in programs that do not expect a different version of libcurl. If you want to enable rh-dotnet permanently, add the following line to your ~/.bashrc file.

source scl_source enable rh-dotnet31

Install the runtime

The .NET Core Runtime allows you to run apps that were made with .NET Core that didn't include the runtime. The commands below install the ASP.NET Core Runtime, which is the most compatible runtime for .NET Core. In your terminal, run the following commands.

subscription-manager repos --enable=rhel-7-server-dotnet-rpms
yum install rh-dotnet31-aspnetcore-runtime-3.1 -y
scl enable rh-dotnet31-aspnetcore-runtime-3.1 bash

Red Hat does not recommend permanently enabling rh-dotnet31-aspnetcore-runtime-3.1 because it may affect other programs. For example, rh-dotnet31-aspnetcore-runtime-3.1 includes a version of libcurl that differs from the base RHEL version. This may lead to issues in programs that do not expect a different version of libcurl. If you want to enable rh-dotnet31-aspnetcore-runtime-3.1 permanently, add the following line to your ~/.bashrc file.

source scl_source enable rh-dotnet31-aspnetcore-runtime-3.1

As an alternative to the ASP.NET Core Runtime, you can install the .NET Core Runtime that doesn't include ASP.NET Core support: replace rh-dotnet31-aspnetcore-runtime-3.1 in the commands above with rh-dotnet31-dotnet-runtime-3.1.

Snap

.NET Core is available from the Snap Store.

A snap is a bundle of an app and its dependencies that works without modification across many different Linux distributions. Snaps are discoverable and installable from the Snap Store. For more information about Snap, see Getting started with Snap.

Only supported versions of .NET Core are available through Snap.

Install the SDK

Snap packages for .NET Core SDK are all published under the same identifier: dotnet-sdk. A specific version of the SDK can be installed by specifying the channel. The SDK includes the coresponding runtime. The following table list the channels:

.NET Core version Snap package
3.1 (LTS) 3.1 or latest/stable
2.1 (LTS) 2.1
.NET 5.0 preview 5.0/beta

Use the snap install command to install a .NET Core SDK snap package. Use the --channel parameter to indicate which version to install. If this parameter is omitted, latest/stable is used. In this example, 3.1 is specified:

sudo snap install dotnet-sdk --classic --channel=3.1

Next, register the dotnet command for the system with the snap alias command:

sudo snap alias dotnet-sdk.dotnet dotnet

This command is formatted as: sudo snap alias {package}.{command} {alias}. You can choose any {alias} name you would like. For example, you could name the command after the specific version installed by snap: sudo snap alias dotnet-sdk.dotnet dotnet31. When you use the command dotnet31, you'll invoke this specific version of .NET. But this is incompatible with most tutorials and examples as they expect a dotnet command to be available.

Install the runtime

Snap packages for .NET Core Runtime are each published under their own package identifier. The following table lists the package identifiers:

.NET Core version Snap package
3.1 (LTS) dotnet-runtime-31
3.0 dotnet-runtime-30
2.2 dotnet-runtime-22
2.1 (LTS) dotnet-runtime-21

Use the snap install command to install a .NET Core Runtime snap package. In this example, .NET Core 3.1 is installed:

sudo snap install dotnet-runtime-31 --classic

Next, register the dotnet command for the system with the snap alias command:

sudo snap alias dotnet-runtime-31.dotnet dotnet

This command is formatted as: sudo snap alias {package}.{command} {alias}. You can choose any {alias} name you would like. For example, you could name the command after the specific version installed by snap: sudo snap alias dotnet-runtime-31.dotnet dotnet31. When you use the command dotnet31, you'll invoke this specific version of .NET. But this is incompatible with most tutorials and examples as they expect a dotnet command to be available.

SSL Certificate errors

When .NET is installed through Snap, it's possible that on some distros the .NET SSL certificates may not be found and you may receive an error similar to the following during restore:

Processing post-creation actions...
Running 'dotnet restore' on /home/myhome/test/test.csproj...
  Restoring packages for /home/myhome/test/test.csproj...
/snap/dotnet-sdk/27/sdk/2.2.103/NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/home/myhome/test/test.csproj]
/snap/dotnet-sdk/27/sdk/2.2.103/NuGet.targets(114,5): error :   The SSL connection could not be established, see inner exception. [/home/myhome/test/test.csproj]
/snap/dotnet-sdk/27/sdk/2.2.103/NuGet.targets(114,5): error :   The remote certificate is invalid according to the validation procedure. [/home/myhome/test/test.csproj]

To resolve this issue, set a few enviornment variables:

export SSL_CERT_FILE=[path-to-certificate-file]
export SSL_CERT_DIR=/dev/null

The certificate location will vary by distro. Here are the locations for the distros where we have experienced the issue.

  • Fedora - /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
  • OpenSUSE - /etc/ssl/ca-bundle.pem
  • Solus - /etc/ssl/certs/ca-certificates.crt

Dependencies

When you install with a package manager, these libraries are installed for you. But, if you manually install .NET Core or you publish a self-contained app, you'll need to make sure these libraries are installed:

  • krb5-libs
  • libicu
  • openssl-libs

If the target runtime environment's OpenSSL version is 1.1 or newer, you'll need to install compat-openssl10.

For more information about the dependencies, see Self-contained Linux apps.

For .NET Core apps that use the System.Drawing.Common assembly, you'll also need the following dependency:

Scripted install

The dotnet-install scripts are used for automation and non-admin installs of the SDK and Runtime. You can download the script from https://dot.net/v1/dotnet-install.sh.

The script defaults to installing the latest SDK long term support (LTS) version, which is .NET Core 3.1. To install the current release, which may not be an (LTS) version, use the -c Current parameter.

./dotnet-install.sh -c Current

To install .NET Core Runtime instead of the SDK, use the --runtime parameter.

./dotnet-install.sh -c Current --runtime aspnetcore

You can install a specific version by altering the -c parameter to indicate the specific version. The following command installs .NET Core SDK 3.1.

./dotnet-install.sh -c 3.1

For more information, see dotnet-install scripts reference.

Manual install

As an alternative to the package managers, you can download and manually install the SDK and runtime. Manual install is usually performed as part of continuous integration testing or on an unsupported Linux distribution. For a developer or user, it's generally better to use a package manager.

If you install .NET Core SDK, you don't need to install the corresponding runtime. First, download a binary release for either the SDK or the runtime from one of the following sites:

Next, extract the downloaded file and use the export command to set variables used by .NET Core and then ensure .NET Core is in PATH.

To extract the runtime and make the .NET Core CLI commands available at the terminal, first download a .NET Core binary release. Then, open a terminal and run the following commands from the directory where the file was saved. The archive file name may be different depending on what you downloaded.

Use the following command to extract the runtime:

mkdir -p "$HOME/dotnet" && tar zxf aspnetcore-runtime-3.1.0-linux-x64.tar.gz -C "$HOME/dotnet"
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet

Use the following command to extract the SDK:

mkdir -p "$HOME/dotnet" && tar zxf dotnet-sdk-3.1.301-linux-x64.tar.gz -C "$HOME/dotnet"
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet

Tip

The preceding export commands only make the .NET Core CLI commands available for the terminal session in which it was run.

You can edit your shell profile to permanently add the commands. There are a number of different shells available for Linux and each has a different profile. For example:

  • Bash Shell: ~/.bash_profile, ~/.bashrc
  • Korn Shell: ~/.kshrc or .profile
  • Z Shell: ~/.zshrc or .zprofile

Edit the appropriate source file for your shell and add :$HOME/dotnet to the end of the existing PATH statement. If no PATH statement is included, add a new line with export PATH=$PATH:$HOME/dotnet.

Also, add export DOTNET_ROOT=$HOME/dotnet to the end of the file.

This approach lets you install different versions into separate locations and choose explicitly which one to use by which application.

Next steps