Install .NET on Linux by using an install script or by extracting binaries
This article demonstrates how to install the .NET SDK or the .NET Runtime on Linux by using the install script or by extracting the binaries. For a list of distributions that support the built-in package manager, see Install .NET on Linux.
You can also install .NET with snap. For more information, see Install the .NET SDK or the .NET Runtime with Snap.
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.
.NET releases
The following table lists the .NET (and .NET Core) releases:
| ✔️ Supported | ❌ Unsupported |
|---|---|
| 6 (LTS) | 3.0 |
| 5 | 2.2 |
| 3.1 (LTS) | 2.1 |
| 2.0 | |
| 1.1 | |
| 1.0 |
For more information about the life cycle of .NET releases, see .NET and .NET Core Support Policy.
Dependencies
It's possible that when you install .NET, specific dependencies may not be installed, such as when manually installing. The following list details Linux distributions that are supported by Microsoft and have dependencies you may need to install. Check the distribution page for more information:
For generic information about the dependencies, see Self-contained Linux apps.
RPM dependencies
If your distribution wasn't previously listed, and is RPM-based, you may need the following dependencies:
- 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.
DEB dependencies
If your distribution wasn't previously listed, and is debian-based, you may need the following dependencies:
- libc6
- libgcc1
- libgssapi-krb5-2
- libicu67
- libssl1.1
- libstdc++6
- zlib1g
Common dependencies
For .NET apps that use the System.Drawing.Common assembly, you'll also need the following dependency:
libgdiplus (version 6.0.1 or later)
Warning
You can install a recent version of libgdiplus by adding the Mono repository to your system. For more information, see https://www.mono-project.com/download/stable/.
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.
Important
Bash is required to run the script.
The script defaults to installing the latest SDK long term support (LTS) version, which is .NET 6. 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 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 SDK 6.0.
./dotnet-install.sh -c 6.0
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 installation is commonly used as part of continuous integration testing or on an unsupported Linux distribution. For a developer or user, it's better to use a package manager.
First, download a binary release for either the SDK or the runtime from one of the following sites. If you install the .NET SDK, you will not need to install the corresponding runtime:
Next, extract the downloaded file and use the export command to set DOTNET_ROOT to the extracted folder's location and then ensure .NET is in PATH. This should make the .NET CLI commands available at the terminal.
Alternatively, after downloading the .NET binary, the following commands may be run from the directory where the file is saved to extract the runtime. This will also make the .NET CLI commands available at the terminal and set the required environment variables. Remember to change the DOTNET_FILE value to the name of the downloaded binary:
DOTNET_FILE=dotnet-sdk-6.0.100-linux-x64.tar.gz
export DOTNET_ROOT=$(pwd)/.dotnet
mkdir -p "$DOTNET_ROOT" && tar zxf "$DOTNET_FILE" -C "$DOTNET_ROOT"
export PATH=$PATH:$DOTNET_ROOT
Tip
The preceding export commands only make the .NET 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
Maklum balas
Kirim dan lihat maklum balas untuk