方法一:官方推荐方式安装
https://www.microsoft.com/net/download/linux-package-manager/ubuntu18-04/sdk-2.1.200
Register Microsoft key and feed
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb
Install .NET SDK
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo apt-get install apt-transport-https sudo apt-get update sudo apt-get install dotnet-sdk-2.1.200
但是以上命令在执行最后一行和倒数第二行的时候总是报错,因为网络问题没有更新软件包源。安装不了。、。
方法二:去github下载SDK通用linux安装包
https://github.com/dotnet/core/blob/master/release-notes/2.1/2.1.2.md
在Downloads标签中找到属于自己版本的安装包,然后下载。
安装命令:
mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-2.1.302-linux-x64.tar.gz -C $HOME/dotnet
export DOTNET_ROOT=$PATH:$HOME/dotnet
export PATH=$PATH:$HOME/dotnet
然后输入“dotnet”,回车,如果没有出错表示安装完成
但上面的方法关闭终端后就失效了,要使其永久生效,需要把最后两行加入到bash脚本
安装命令参考:https://www.microsoft.com/net/download/thank-you/dotnet-sdk-2.1.302-linux-x64-binaries(不完全相同)