Skip to content

Latest commit

 

History

History
115 lines (76 loc) · 5.4 KB

linux-snap-runtime.md

File metadata and controls

115 lines (76 loc) · 5.4 KB
title description author ms.author ms.date ms.topic ms.custom
Install .NET Runtime on Linux with Snap
Learn about how to install the .NET Runtime snap package. Canonical maintains and supports .NET-related snap packages.
adegeo
adegeo
05/22/2024
install-set-up-deploy
linux-related-content

Install .NET Runtime with Snap

This article describes how to install the .NET Runtime snap package. .NET Runtime snap packages are provided by and maintained by Canonical. Snaps are a great alternative to the package manager built into your Linux distribution.

A snap is a bundle of an app and its dependencies that works 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 installations of .NET may have problems running .NET tools. If you wish to use .NET tools, we recommend that you install .NET using the dotnet-install script or the package manager for the particular Linux distribution.

Prerequisites

  • Linux distribution that supports snap.
  • snapd the snap daemon.

Your Linux distribution might already include snap. Try running snap from a terminal to see if the command works. For a list of supported Linux distributions, and instructions on how to install snap, see Installing snapd.

.NET releases

[!INCLUDE supported-versions]

1. Install the runtime

The following steps install the .NET 8 runtime snap package:

  1. Open a terminal.

  2. Use snap install to install the .NET Runtime snap package. For example, the following command installs the .NET 8 runtime.

    sudo snap install dotnet-runtime-80

Each .NET Runtime is published as an individual snap package. The following table lists the packages:

.NET version Snap package .NET version supported by Microsoft
8 (STS) dotnet-runtime-80 Yes
7 (STS) dotnet-runtime-70 No
6 (LTS) dotnet-runtime-60 Yes
5 dotnet-runtime-50 No
3.1 dotnet-runtime-31 No
3.0 dotnet-runtime-30 No
2.2 dotnet-runtime-22 No
2.1 dotnet-runtime-21 No

2. Enable the dotnet command

When the .NET runtime snap package is installed, the dotnet command isn't automatically configured. Use the snap alias command to use the dotnet command from the terminal. The command is formatted as: sudo snap alias {package}.{command} {alias}. The following example maps the dotnet command:

sudo snap alias dotnet-runtime-80.dotnet dotnet

3. 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-runtime-80 snap, use the following command to set the environment variable to where .NET is located:

export DOTNET_ROOT=/snap/dotnet-runtime-80/current

Export the environment variable permanently

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-runtime-80/current.

Troubleshooting

The dotnet terminal command doesn't work

Snap packages can map an alias to a command provided by the package. The .NET Runtime snap packages don't automatically lias the dotnet command. To alias the dotnet command to the snap package, use the following command:

sudo snap alias dotnet-runtime-80.dotnet dotnet

Substitute dotnet-runtime-80 with the name of your runtime package.

Can't install Snap on WSL2

systemd must be enabled on the WSL2 instance before Snap can be installed.

  1. Open /etc/wsl.conf in a text editor of your choice.

  2. Paste in the following configuration:

    [boot]
    systemd=true
  3. Save the file and restart the WSL2 instance through PowerShell. Use the wsl.exe --shutdown command.

Related content