Linux下安装.NET Core

环境

{
    "操作系统":"CentOS 7.5 64位",   
    "CPU":"1核",
    "内存":"2GB",
    "公网带宽":"1Mbps"
}

0.[校验]先查看系统是否已经安装了dotnet


[root@VM_0_12_centos /]# dotnet
-bash: dotnet: command not found

如果返回"command not found",继续看下去,
如果已经安装了dotnet,请关闭本页面.

1.[先决条件]查看yum版本号


[root@VM_0_12_centos /]# yum --version
3.4.3
[root@VM_0_12_centos /]# yum update
//省略N多代码...
Complete!

关yum啥事情?
1.看了篇博客,说要更新下yum版本,所以我查看了下yum的版本,
紧接着不管现在的版本号,就更新了yum的版本...
2.微软官方文档上也是用yum这种方式来进行安装的.
This article describes how to use a package manager to install .NET Core on CentOS 7.

2.[正式开始.热身阶段]开始之前,先需要做以下准备

  • Register the Microsoft key
  • register the product repository
  • Install required dependencies

[root@VM_0_12_centos ~]# sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
Retrieving https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:packages-microsoft-prod-1.0-1    ################################# [100%]

虽然他们说了这么多,但是我只是最后执行了一下,最后给的命令,

没有太关注细节...(对,我相信这条命令一定把所有的依赖都处理掉了...)

2.5[正式开始.]曲折的安装SDKs之路

为什么这个步骤是"2.5"呢...因为刚开始的时候,把这个步骤忘记了,

我觉得只要我安装{ASP.NET Core runtime},会自动将这个依赖给安装上呢...

直到输入"dotnet --version",根据提示信息才发现问题,详情见下文.


[root@VM_0_12_centos ~]# sudo yum install dotnet-sdk-3.0
//省略N多输出...
[Errno 2] No such file or directory: '/tmp/yum_save_tx.2019-11-29.13-12.0qLwqf.yumtx'

很明显报错了.搜索错误.得出以下老司机神奇代码↓任意门GoGoGo


[root@VM_0_12_centos ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@VM_0_12_centos ~]# yum makecache

然后怀着一盒忐忑的心,再次执行了一下命令

[root@VM_0_12_centos ~]# sudo yum install dotnet-sdk-3.0
//省略N多输出...

Installed:
  dotnet-sdk-3.0.x86_64 0:3.0.101-1

Dependency Installed:
  aspnetcore-targeting-pack-3.0.x86_64 0:3.0.1-1
  dotnet-apphost-pack-3.0.x86_64 0:3.0.1-1
  dotnet-targeting-pack-3.0.x86_64 0:3.0.0-1
  netstandard-targeting-pack-2.1.x86_64 0:2.1.0-1

Complete!

3.[正式开始.runtime的抉择]Install the ASP.NET Core runtime

If you're installing the runtime, we suggest you install the ASP.NET Core runtime, as it includes both .NET Core and ASP.NET Core runtimes.

官网推荐直接安装{ASP.NET Core runtime},因为全啊...


[root@VM_0_12_centos ~]# sudo yum install aspnetcore-runtime-3.0
//省略N多输出...
Installed:
  aspnetcore-runtime-3.0.x86_64 0:3.0.1-1

Dependency Installed:
  dotnet-host.x86_64 0:3.0.1-1         dotnet-hostfxr-3.0.x86_64 0:3.0.1-1
  dotnet-runtime-3.0.x86_64 0:3.0.1-1  dotnet-runtime-deps-3.0.x86_64 0:3.0.1-1
  libicu.x86_64 0:50.2-3.el7

Complete!

从上面的也看得出来,确实安装{ASP.NET Core runtime}的时候,
会自动安装其依赖{dotnet-runtime-3.0.x86_64}

4.[完美结束]打完收工

[root@VM_0_12_centos ~]# dotnet --version
3.0.101

75a4650dfdc40a0cb19463668550862b.png

终于Ok了...

9.[号外]中途的小意外

安装完了,看下是否安装好了,结果出现了下面的提示:

[root@VM_0_12_centos ~]# dotnet --version
  It was not possible to find any installed .NET Core SDKs
  Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download

提示很明显,没有安装{.NET Core SDKs},可能因为我看了这句话,

If you're installing the runtime, we suggest you install the ASP.NET Core runtime, as it includes both .NET Core and ASP.NET Core runtimes.

理所当然觉得安装了{ASP.NET Core runtime}就万事大吉了.

后知后觉的理下丝路:

//1.安装{ASP.NET Core runtime}会安装
[
    "dotnet-host.x86_64",
    "dotnet-runtime-3.0.x86_64",
    "libicu.x86_64"
]
//2.必须要单独安装
{
    ".NET Core SDKs"
}
//3.{ASP.NET Core runtime}和{".NET Core SDKs"}关系可以参考
[
    "Jre",
    "JDK"
]

然后我就添加了步骤"2.5"

摘抄

扩展

posted @ 2019-11-30 12:46  zh89233  阅读(2503)  评论(0编辑  收藏  举报