安装 .NET 之前,运行以下命令,将 Microsoft 包签名密钥添加到受信任密钥列表,并添加包存储库。
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
安装 SDK
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
查看版本
dotnet –version
查看SDK
dotnet –info
.NET SDK (reflecting any global.json):
Version: 5.0.102
Commit: 71365b4d42
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.102/
Host (useful for support):
Version: 5.0.2
Commit: cb5f173b96
.NET SDKs installed:
5.0.102 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
检查SDK版本
dotnet –list-sdks
5.0.102 [/usr/share/dotnet/sdk]
检查运行时版本
dotnet –list-runtimes
Microsoft.AspNetCore.App 5.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
通过 docker 运行
拉取镜像
docker pull mcr.microsoft.com/dotnet/sdk
docker pull mcr.microsoft.com/dotnet/aspnet
docker pull mcr.microsoft.com/dotnet/runtime
docker pull mcr.microsoft.com/dotnet/runtime-deps
docker pull mcr.microsoft.com/dotnet/samples
运行一个简单的应用
docker run –rm mcr.microsoft.com/dotnet/samples
运行一个web应用
docker run -it –rm -p 8000:80 –name aspnetcore_sample mcr.microsoft.com/dotnet/samples:aspnetapp
通过 http://localhost:8000/ 访问