# Install the .NET SDK or the .NET Runtime with Snap

Use a Snap package to install the .NET SDK or .NET Runtime. Snaps are a great alternative to the package manager built into your Linux distribution. This article describes how to install .NET through Snap.

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.

Caution

Snap packages aren't supported in WSL2 on Windows 10. As an alternative, use the dotnet-install script or the package manager for the particular WSL2 distribution. It's not recommended but you can try to enable snap with an unsupported workaround from the snapcraft forums.

## .NET releases

Only ✔️ supported versions of .NET SDK are available through Snap. All versions of the .NET Runtime are available through snap starting with version 2.1. The following table lists the .NET (and .NET Core) releases:

✔️ Supported ❌ Unsupported
5.0 3.0
3.1 (LTS) 2.2
2.1 (LTS) 2.0
1.1
1.0

For more information about the life cycle of .NET releases, see .NET Core and .NET 5 Support Policy.

## SDK or Runtime

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 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 is already installed.

## Install the SDK

Snap packages for the .NET 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 corresponding runtime. The following table lists the channels:

.NET version Snap package or channel
5.0 5.0 or latest/stable
3.1 (LTS) 3.1 or lts/stable
2.1 (LTS) 2.1

Use the snap install command to install a .NET 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, 5.0 is specified:

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


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 dotnet50. When you use the command dotnet50, you'll invoke this specific version of .NET. But choosing a different alias is incompatible with most tutorials and examples as they expect a dotnet command to be used.

## Install the runtime

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

.NET version Snap package
5.0 dotnet-runtime-50
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 Runtime snap package. In this example, .NET 5.0 is installed:

sudo snap install dotnet-runtime-50 --classic


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

sudo snap alias dotnet-runtime-50.dotnet dotnet


The 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-50.dotnet dotnet50. When you use the command dotnet50, you'll invoke a specific version of .NET. But choosing a different alias is incompatible with most tutorials and examples as they expect a dotnet command to be available.

## Export the install location

The DOTNET_ROOT environment variable is often used by tools to determine where .NET is installed. When .NET is installed through Snap, this environment variable isn't configured. You should configure the DOTNET_ROOT environment variable in your profile. The path to the snap uses the following format: /snap/{package}/current. For example, if you installed the dotnet-sdk snap, use the following command to set the environment variable to where .NET is located:

export DOTNET_ROOT=/snap/dotnet-sdk/current


Tip

The preceding export command only sets the environment variable 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 export DOTNET_ROOT=/snap/dotnet-sdk/current.

## TLS/SSL Certificate errors

When .NET is installed through Snap, it's possible that on some distros the .NET TLS/SSL certificates may not be found and you may receive an error 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 problem, set a few environment 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 the issue has been experienced.

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