There three choices install .net SDK on OS.
1.Install the .NET SDK or the .NET Runtime with Snap.
2.Install the .NET SDK or the .NET Runtime with a script.
3.Install the .NET SDK or the .NET Runtime manually.
Table of Contents
Install .NET on Linux without using a package manager
Manual install
way 1:Install .NET on Linux by using an install script
way 2:
https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#manual-install
DOTNET_FILE=dotnet-sdk-8.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:$DOTNET_ROOT/tools
包管理器
(Microsoft 源)https://learn.microsoft.com/zh-cn/dotnet/core/install/linux-ubuntu#register-the-microsoft-package-repository
包管理器
(Ubuntu 源)https://learn.microsoft.com/zh-cn/dotnet/core/install/linux-ubuntu#supported-distributions
Important
Package manager installs are only supported on the x64 architecture.
Other architectures, such as Arm, must install .NET by some other means such as with Snap, an installer script, or through a manual binary installation.
Manual installation is commonly used as part of continuous integration testing or on an unsupported Linux distribution.
https://github.com/dotnet/core/blob/master/release-notes/5.0/5.0.0/5.0.0-install-instructions.md
os:Ubuntu 18.04*64
.net x version:.net 7.01
.NET 7.0 download url:https://dotnet.microsoft.com/download/dotnet/7.0
https://aka.ms/dotnet-download
You can download .NET 7.0, for Windows, macOS, and Linux, for x86, x64, Arm32, Arm64.
.Net 9.x
step 1.downloading an installer or binary release
step 2.
DOTNET_FILE=dotnet-sdk-9.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:$DOTNET_ROOT/tools
snap
sudo snap install dotnet-sdk --classic
https://learn.microsoft.com/zh-cn/dotnet/core/install/linux-snap-sdk
script
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
https://learn.microsoft.com/zh-cn/dotnet/core/install/linux-scripted-manual#scripted-install
Install using deb/rpm packages
step 1:
Create a directory to use for the download location and change into that directory. For example .
# mkdir $HOME/dotnet_install
cd $HOME/dotnet_install
output:
root@vultr:~/dotnet_install
step 2:get
Open a terminal and run the following commands:
download come from:
https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-5.0.100-linux-x64-binaries
wget wget https://download.visualstudio.microsoft.com/download/pr/2431d5ac-f5db-4bb1-bcf0-4a2d9725d4e4/1b0747add72af919754509f83ad08660/dotnet-runtime-7.0.3-linux-x64.tar.gz
output:
Saving to: ‘dotnet-runtime-7.0.3-linux-x64.tar.gz’
.Net Releases Index
https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json
{
"releases-index": [
{
"channel-version": "7.0",
"latest-release": "7.0.3",
"latest-release-date": "2023-02-14",
"security": true,
"latest-runtime": "7.0.3",
"latest-sdk": "7.0.200",
"product": ".NET",
"release-type" : "sts",
"support-phase": "active",
"eol-date": "2024-05-14",
"releases.json": "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json"
},
https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json
{
"channel-version": "7.0",
"latest-release": "7.0.3",
"latest-release-date": "2023-02-14",
"latest-runtime": "7.0.3",
"latest-sdk": "7.0.200",
"release-type" : "sts",
"support-phase": "active",
"eol-date": "2024-05-14",
"lifecycle-policy": "https://aka.ms/dotnetcoresupport",
"releases": [
{
"release-date": "2023-02-14",
"release-version": "7.0.3",
"security": true,
"cve-list": [
{
"cve-id": "CVE-2023-21808",
"cve-url": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-21808"
}
],
"release-notes": "https://github.com/dotnet/core/blob/main/release-notes/7.0/7.0.3/7.0.3.md",
"runtime": {
"version": "7.0.3",
"version-display": "7.0.3",
"vs-version": "17.5.0, 17.4.5",
"vs-mac-version": "17.4.5",
"files": [
{
"name": "dotnet-runtime-linux-arm.tar.gz",
"rid": "linux-arm",
"url": "https://download.visualstudio.microsoft.com/download/pr/d5489c60-2a6a-46da-a8d4-e216e929ed58/b50cc86b9b6d2346611f2a0caeefcdc8/dotnet-runtime-7.0.3-linux-arm.tar.gz",
"hash": "e26aa9caef1b75d7d2fdf48b40ec941347a24f9f2862f54af8dce8447931ff9ae319bfb955a86c2375c79df35731f3c6d6c642dcf5f7726c49e4fc6668ae2fa5"
},
step 3:Run the script
tar zxf dotnet-runtime-7.0.3-linux-x64.tar.gz -C /usr/share/dotnet
output
root@iZbp18j0fr5xhywnh03waxZ:~# dotnet --info
.NET SDK:
Version: 7.0.100
Commit: e12b7af219
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/7.0.100/
Host:
Version: 7.0.3
Architecture: x64
Commit: 0a2bda10e8
.NET SDKs installed:
5.0.408 [/usr/share/dotnet/sdk]
6.0.100 [/usr/share/dotnet/sdk]
6.0.403 [/usr/share/dotnet/sdk]
7.0.100 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.17 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.17 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
How to check that .NET is already installed
You can see which versions of the .NET SDK are currently installed with a terminal. Open a terminal and run the following command.
Check SDK versions & Check runtime versions
dotnet --list-sdks
dotnet --list-runtimes
output
~/dotnet_install# dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.101
Commit: d05174dc5a
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/5.0.101/
Host (useful for support):
Version: 5.0.1
Commit: b02e13abab
.NET SDKs installed:
5.0.100 [/usr/share/dotnet/sdk]
5.0.101 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
root#:~/dotnet_install# dotnet --list-runtimes
Microsoft.AspNetCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
aliyun vps
Install using deb/rpm packages on aliyun Ubuntu 18.04*64
lsb_release -a
LSB Version: core-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic
aliyun install error
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'aspnetcore-runtime-5.0' instead of '/root/dotnet_install/dotnet_packages/aspnetcore-runtime-5.0.0-rc.1.20451.17-x64.deb'
Note, selecting 'aspnetcore-targeting-pack-5.0' instead of '/root/dotnet_install/dotnet_packages/aspnetcore-targeting-pack-5.0.0-rc.1.20451.17.deb'
Note, selecting 'dotnet-apphost-pack-5.0' instead of '/root/dotnet_install/dotnet_packages/dotnet-apphost-pack-5.0.0-rc.1.20451.14-x64.deb'
Note, selecting 'dotnet-host' instead of '/root/dotnet_install/dotnet_packages/dotnet-host-5.0.0-rc.1.20451.14-x64.deb'
Note, selecting 'dotnet-hostfxr-5.0' instead of '/root/dotnet_install/dotnet_packages/dotnet-hostfxr-5.0.0-rc.1.20451.14-x64.deb'
Note, selecting 'dotnet-runtime-5.0' instead of '/root/dotnet_install/dotnet_packages/dotnet-runtime-5.0.0-rc.1.20451.14-x64.deb'
Note, selecting 'dotnet-runtime-deps-5.0' instead of '/root/dotnet_install/dotnet_packages/dotnet-runtime-deps-5.0.0-rc.1.20451.14-x64.deb'
Note, selecting 'dotnet-sdk-5.0' instead of '/root/dotnet_install/dotnet_packages/dotnet-sdk-5.0.100-rc.1.20452.10-x64.deb'
Note, selecting 'dotnet-targeting-pack-5.0' instead of '/root/dotnet_install/dotnet_packages/dotnet-targeting-pack-5.0.0-rc.1.20451.14-x64.deb'
Note, selecting 'netstandard-targeting-pack-2.1' instead of '/root/dotnet_install/dotnet_packages/netstandard-targeting-pack-2.1.0-x64.deb'
The following packages were automatically installed and are no longer required:
linux-headers-4.15.0-52 linux-headers-4.15.0-52-generic linux-image-4.15.0-52-generic linux-modules-4.15.0-52-generic linux-modules-extra-4.15.0-52-generic
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
aspnetcore-runtime-5.0 aspnetcore-targeting-pack-5.0 dotnet-apphost-pack-5.0 dotnet-hostfxr-5.0 dotnet-runtime-5.0 dotnet-runtime-deps-5.0 dotnet-sdk-5.0 dotnet-targeting-pack-5.0
The following packages will be upgraded:
dotnet-host
The following packages will be DOWNGRADED:
netstandard-targeting-pack-2.1
1 upgraded, 8 newly installed, 1 downgraded, 0 to remove and 205 not upgraded.
E: Packages were downgraded and -y was used without --allow-downgrades.
root@iZuf6hn15mpmrtypv9ltogZ:~/dotnet_install# pwd
/root/dotnet_install
root@iZuf6hn15mpmrtypv9ltogZ:~/dotnet_install# ls -l
total 90640
-rw-r--r-- 1 root root 92798272 Sep 16 23:49 dotnet-5.0.0-rc.1-deb.tar.gz
drwxr-xr-x 2 501 staff 4096 Sep 12 07:27 dotnet_packages
-rw-r--r-- 1 root root 6472 Sep 16 19:07 install-dotnet-preview.sh
instead of
cd dotnet_install
dotnet_install# apt install -y --allow-downgrades ./dotnet_packages/*
output:
.NET SDK (reflecting any global.json):
Version: 5.0.100
Commit: 5044b93829
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/5.0.100/
Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7
.NET SDKs installed:
3.0.100 [/usr/share/dotnet/sdk]
3.1.301 [/usr/share/dotnet/sdk]
5.0.100-rc.2.20479.15 [/usr/share/dotnet/sdk]
5.0.100 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0-rc.2.20475.17 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-rc.2.20475.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
# dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.100-rc.1.20452.10
Commit: 473d1b592e
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/5.0.100-rc.1.20452.10/
Host (useful for support):
Version: 5.0.0-rc.1.20451.14
Commit: 38017c3935
.NET SDKs installed:
5.0.100-rc.1.20452.10 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
upgrade net5.x on Ubuntu 18.04*64
detail:https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#1804-
step 1:
Open a terminal and run the following commands:
cd dotnet_install
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
output
Saving to: ‘packages-microsoft-prod.deb’
#ls -l
-rw-r--r-- 1 root root 92798272 Sep 16 2020 dotnet-5.0.0-rc.1-deb.tar.gz
-rw-r--r-- 1 root root 92970717 Oct 15 2020 dotnet-5.0.0-rc.2-deb.tar.gz
-rw-r--r-- 1 root root 35418 Nov 11 2020 dotnet-install.sh
drwxr-xr-x 2 501 staff 4096 Oct 13 2020 dotnet_packages
-rw-r--r-- 1 root root 137519004 Nov 5 2020 dotnet-sdk-5.0.100-linux-x64.tar.gz
-rw-r--r-- 1 root root 7088 Oct 15 2020 install-dotnet-preview.sh
-rw-r--r-- 1 root root 6256 Jan 3 2019 packages-microsoft-prod.deb
#sudo dpkg -i packages-microsoft-prod.deb
Configuration file '/etc/apt/sources.list.d/microsoft-prod.list'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** microsoft-prod.list (Y/I/N/O/D/Z) [default=N] ? y
Installing new version of config file /etc/apt/sources.list.d/microsoft-prod.list
step 2: check that .NETx version is already installed
dotnet --info
output
.NET SDK (reflecting any global.json):
Version: 5.0.101
Commit: d05174dc5a
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/5.0.101/
Host (useful for support):
Version: 5.0.1
Commit: b02e13abab
.NET SDKs installed:
3.0.100 [/usr/share/dotnet/sdk]
3.1.301 [/usr/share/dotnet/sdk]
5.0.100 [/usr/share/dotnet/sdk]
5.0.101 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
step 3:Install the SDK&Install the runtime
sudo apt-get update
sudo apt-get install -y apt-transport-https
sudo apt-get update
sudo apt-get install -y dotnet-sdk-5.0
sudo apt-get update
sudo apt-get install -y apt-transport-https
sudo apt-get update
sudo apt-get install -y aspnetcore-runtime-5.0
Here's what the script does.
Detects the distribution and version. If it's in the 5.0 Supported OS list, the script will continue.
Determines if additional system dependencies or utilities are needed to successfully complete and install them. For example tar is used to unpack that installer packages.
Downloads the tar.gz containing the .NET preview installer packages for the detected distribution.
Downloads the system dependency installer, if needed.
Expands the tar.gz into ./dotnet_packages
Attempts to install the contents of ./dotnet_packages using rpm or dpkg, as appropriate, for the detected distribution.
dotnet-runtime-5.0:If only the .NET Core Runtime is needed, install dotnet-runtime-5.0 using your package manager.
aspnetcore-runtime-5.0: If you also need ASP.NET Core functionality, installing aspnetcore-runtime-5.0 will install both the ASP Runtime and .NET Core Runtime.
Install .Net 8.x on Ubuntu 18.04 - Manual install 20231120 run ok
This article discusses how to install .NET 8 on Ubuntu 18.04; .NET 6 and .NET 7 are supported. .NET 8 are not supported.source:https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-1804
must install .NET 8 by through a manual binary installation.
https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json
https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json
https://download.visualstudio.microsoft.com/download/pr/fc4b4447-45f2-4fd2-899a-77eb1aed7792/6fd52c0c61f064ddc7fe7684e841f491/dotnet-runtime-8.0.0-linux-x64.tar.gz
tar zxf dotnet-runtime-8.0.0-linux-x64.tar.gz -C /usr/share/dotnet
https://download.visualstudio.microsoft.com/download/pr/5226a5fa-8c0b-474f-b79a-8984ad7c5beb/3113ccbf789c9fd29972835f0f334b7a/dotnet-sdk-8.0.100-linux-x64.tar.gz
tar zxf dotnet-sdk-8.0.100-linux-x64.tar.gz -C /usr/share/dotnet
a list of Ubuntu Supported .NET versions 20231120 for .net 8
https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#1804-
Migrate from ASP.NET Core 3.1 to 5.0