在Linux中运行.net core 项目必须要有.net core SDK 环境。之前配置过几次,但由于没有做总结。过了几天又配置的时候
感觉特别陌生,今天就记录一次.net core SDK 的安装,希望能帮到用到的朋友。
在Linux中安装.net core SDK主要又两种方式,一种是包管理安装,另一种是源码安装
这里以Centos7为例
一.包管理安装
这里给出微软的官方教程:https://dotnet.microsoft.com/download/linux-package-manager/rhel7/sdk-2.2.402
1.注册Microsoft密钥、注册产品存储库并安装所需的依赖项
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
2.通过yum安装.net core SDK(yum未配置的可参考此教程)
sudo yum install dotnet-sdk-2.2
二.源码安装(这种方法相对来说比较麻烦,需要自己配置环境变量)
1.从微软官方网站下载安装包
2.将下载下来的安装包移动到 /var/dotnet
mkdir /var/dotnet 创建文件夹
mv dotnet-sdk-2.2.402-linux-x64.tar.gz /var/dotnet/ 移动到创建的文件夹下
cd /var/dotnet
tar -zxvf dotnet-sdk-2.2.402-linux-x64.tar.gz 解压安装包
3.配置环境变量(永久配置)
vim /etc/profile 编辑配置文件
在文件的末尾添加以下命令
export PATH=$PATH:/var/dotnet/
加载配置,使其立即生效
source /etc/profile