.netcore入门1:linux上安装.net core sdk 2.2(离线安装和yum仓库安装)

实验环境:
操作系统:最小化安装的centos7.6 x64
sdk:dotnet-sdk-2.2.401-linux-x64-binarie
说明:
linux上安装dotnetcore sdk有两种方式,一个是使用编译好的离线安装包,一个是使用微软提供的yum仓库。

一、使用离线sdk安装包安装sdk

1.1 下载 dotnet-sdk

访问官网:https://dotnet.microsoft.com/download/dotnet-core/2.2
.netcore入门1:linux上安装.net core sdk 2.2(离线安装和yum仓库安装)_第1张图片
直接点击上面的x64就可以下载,下载后的文件是:
在这里插入图片描述

1.2 安装依赖

输入命令:yum install libunwind libicu -y

[root@localhost ~]# yum install libwunwind libicu -y
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                  | 3.6 kB  00:00:00     
extras                                                                                                                                                                | 3.4 kB  00:00:00     
updates                                                                                                                                                               | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                                                                                         | 166 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                                                                                                                     | 215 kB  00:00:00     
(3/4): base/7/x86_64/primary_db                                                                                                                                       | 6.0 MB  00:00:02     
(4/4): updates/7/x86_64/primary_db                                                                                                                                    | 7.4 MB  00:00:11     
没有可用软件包 libwunwind。
正在解决依赖关系
--> 正在检查事务
---> 软件包 libicu.x86_64.0.50.1.2-17.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=============================================================================================================================================================================================
 Package                                     架构                                        版本                                                源                                         大小
=============================================================================================================================================================================================
正在安装:
 libicu                                      x86_64                                      50.1.2-17.el7                                       base                                      6.9 M

事务概要
=============================================================================================================================================================================================
安装  1 软件包

总下载量:6.9 M
安装大小:24 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/libicu-50.1.2-17.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY=====================-      ] 4.3 MB/s | 6.2 MB  00:00:00 ETA 
libicu-50.1.2-17.el7.x86_64.rpm 的公钥尚未安装
libicu-50.1.2-17.el7.x86_64.rpm                                                                                                                                       | 6.9 MB  00:00:00     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) "
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 软件包     : centos-release-7-6.1810.2.el7.centos.x86_64 (@anaconda)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : libicu-50.1.2-17.el7.x86_64                                                                                                                                              1/1 
  验证中      : libicu-50.1.2-17.el7.x86_64                                                                                                                                              1/1 

已安装:
  libicu.x86_64 0:50.1.2-17.el7                                                                                                                                                              

完毕!
[root@localhost ~]#

1.3 上传sdk包并解压到/usr/local/dotnet目录

1). 使用上传dotnet-sdk-2.2.401-linux-x64.tar.gz到/usr/local目录

2). 创建/usr/local/dotnet目录并将sdk包解压到这个目录中:

[root@localhost local]# pwd
/usr/local
[root@localhost local]# ll
总用量 166220
drwxr-xr-x. 2 root root         6 4月  11 2018 bin
-rw-r--r--. 1 root root 170205501 8月  29 11:19 dotnet-sdk-2.2.401-linux-x64.tar.gz
drwxr-xr-x. 2 root root         6 4月  11 2018 etc
drwxr-xr-x. 2 root root         6 4月  11 2018 games
drwxr-xr-x. 2 root root         6 4月  11 2018 include
drwxr-xr-x. 2 root root         6 4月  11 2018 lib
drwxr-xr-x. 2 root root         6 4月  11 2018 lib64
drwxr-xr-x. 2 root root         6 4月  11 2018 libexec
drwxr-xr-x. 2 root root         6 4月  11 2018 sbin
drwxr-xr-x. 5 root root        49 8月  29 11:25 share
drwxr-xr-x. 2 root root         6 4月  11 2018 src
[root@localhost local]# mkdir dotnet
[root@localhost local]# tar -zxf dotnet-sdk-2.2.401-linux-x64.tar.gz -C dotnet
[root@localhost local]# cd dotnet
[root@localhost dotnet]# ll
总用量 136
-rwxr-xr-x. 1 1004 27 105872 6月  19 03:49 dotnet
drwxr-xr-x. 3 1004 27     17 7月  13 06:58 host
-rw-r--r--. 1 1004 27   1083 6月  19 03:45 LICENSE.txt
drwxr-xr-x. 3 1004 27     21 7月  13 06:58 sdk
drwxr-xr-x. 5 1004 27     99 7月  13 06:58 shared
-rw-r--r--. 1 1004 27  27700 6月  19 03:45 ThirdPartyNotices.txt
[root@localhost dotnet]#

1.4 注意目录/usr/local/dotnet/sdk/NuGetFallbackFolder

你会发现,解压的结果中并没有这个目录。这里做一个观察,因为后面你会看到,一旦执行dotnet命令,即使是dotnet --version这个目录也会立马生成。

1.5 配置环境变量

在/etc/profile文件末尾加上两行:

export DOTNET_ROOT=/usr/local/dotnet
export PATH=$DOTNET_ROOT:$PATH

执行 source /etc/profile使改动生效:

[root@localhost dotnet]# source /etc/profile

1.6 验证dotnetcore环境:dotnet --version或dotnet --info

.netcore入门1:linux上安装.net core sdk 2.2(离线安装和yum仓库安装)_第2张图片

1.7 注意目录/usr/local/dotnet/sdk/NuGetFallbackFolder

可以看到这个目录已经生成了,但是里面是空的。因为这里存放的是编译需要的依赖库,所以现在我们执行命令dotnet restore将这些依赖缓存一下(报错提示不用管):

[root@localhost ~]# dotnet restore

Configuring...
--------------
A command is running to populate your local package cache to improve restore speed and enable offline access. This command takes up to one minute to complete and only runs once.
Decompressing 100% 5693 ms
Expanding 100% 20575 ms
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
[root@localhost ~]# 

执行完后就会发现里面已经缓存了大量的依赖库:
.netcore入门1:linux上安装.net core sdk 2.2(离线安装和yum仓库安装)_第3张图片

1.8 推测dotnet安装目录结构(个人推测)

.netcore入门1:linux上安装.net core sdk 2.2(离线安装和yum仓库安装)_第4张图片

  • host目录下最终就一个文件:/usr/local/dotnet/host/fxr/2.2.6/libhostfxr.so
  • sdk目录下就一个目录2.2.401这个代表的是dotnetcore skd的版本,它下面就是dotnet开发中用到的命令、组件什么的
  • shared目录下有三个目录Microsoft.AspNetCore.All、Microsoft.AspNetCore.App和Microsoft.NETCore.App,其中"Microsoft.AspNetCore.App"表示asp.net core的运行环境(不包含外部依赖),“Microsoft.NETCore.App”表示netcore的运行环境,“Microsoft.AspNetCore.All”里面的内容在“Microsoft.AspNetCore.App”的基础上包含了外部依赖。最后他们的下级目录都是以版本号命名的“2.2.6”, 具体的区别可去官网上查看:包、元包和框架
  • 注意目录: sdk/2.2.401/Roslyn,这是dotnet的编译器目录, bincore/csc.dll就是编译器,它也是c#编写的。

二、使用yum仓库安装

查看官方文档:https://dotnet.microsoft.com/download/linux-package-manager/centos/sdk-2.2.401
.netcore入门1:linux上安装.net core sdk 2.2(离线安装和yum仓库安装)_第5张图片
按照上面的步骤:

2.1 添加微软仓库:rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm

.netcore入门1:linux上安装.net core sdk 2.2(离线安装和yum仓库安装)_第6张图片

2.2 更新仓库:yum update

输入命令后按照提示向下走即可。

2.3 安装dotnet:yum install dotnet-sdk-2.2

[root@localhost ~]# yum install dotnet-sdk-2.2
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
base                                                                                                                                                                  | 3.6 kB  00:00:00     
extras                                                                                                                                                                | 3.4 kB  00:00:00     
packages-microsoft-com-prod                                                                                                                                           | 2.9 kB  00:00:00     
updates                                                                                                                                                               | 3.4 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 dotnet-sdk-2.2.x86_64.0.2.2.401-1 将被 安装
--> 正在处理依赖关系 dotnet-runtime-2.2 >= 2.2.6,它被软件包 dotnet-sdk-2.2-2.2.401-1.x86_64 需要
--> 正在处理依赖关系 aspnetcore-runtime-2.2 >= 2.2.6,它被软件包 dotnet-sdk-2.2-2.2.401-1.x86_64 需要
--> 正在检查事务
---> 软件包 aspnetcore-runtime-2.2.x86_64.0.2.2.6-1 将被 安装
---> 软件包 dotnet-runtime-2.2.x86_64.0.2.2.6-1 将被 安装
--> 正在处理依赖关系 dotnet-runtime-deps-2.2 >= 2.2.6,它被软件包 dotnet-runtime-2.2-2.2.6-1.x86_64 需要
--> 正在处理依赖关系 dotnet-hostfxr-2.2 >= 2.2.6,它被软件包 dotnet-runtime-2.2-2.2.6-1.x86_64 需要
--> 正在检查事务
---> 软件包 dotnet-hostfxr-2.2.x86_64.0.2.2.6-1 将被 安装
--> 正在处理依赖关系 dotnet-host >= 2.2.6,它被软件包 dotnet-hostfxr-2.2-2.2.6-1.x86_64 需要
---> 软件包 dotnet-runtime-deps-2.2.x86_64.0.2.2.6-1 将被 安装
--> 正在处理依赖关系 libicu,它被软件包 dotnet-runtime-deps-2.2-2.2.6-1.x86_64 需要
--> 正在检查事务
---> 软件包 dotnet-host.x86_64.0.2.2.6-1 将被 安装
---> 软件包 libicu.x86_64.0.50.1.2-17.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=============================================================================================================================================================================================
 Package                                            架构                              版本                                      源                                                      大小
=============================================================================================================================================================================================
正在安装:
 dotnet-sdk-2.2                                     x86_64                            2.2.401-1                                 packages-microsoft-com-prod                            116 M
为依赖而安装:
 aspnetcore-runtime-2.2                             x86_64                            2.2.6-1                                   packages-microsoft-com-prod                             30 M
 dotnet-host                                        x86_64                            2.2.6-1                                   packages-microsoft-com-prod                             44 k
 dotnet-hostfxr-2.2                                 x86_64                            2.2.6-1                                   packages-microsoft-com-prod                            196 k
 dotnet-runtime-2.2                                 x86_64                            2.2.6-1                                   packages-microsoft-com-prod                             27 M
 dotnet-runtime-deps-2.2                            x86_64                            2.2.6-1                                   packages-microsoft-com-prod                            2.8 k
 libicu                                             x86_64                            50.1.2-17.el7                             base                                                   6.9 M

事务概要
=============================================================================================================================================================================================
安装  1 软件包 (+6 依赖软件包)

总计:180 M
总下载量:180 M
安装大小:197 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/packages-microsoft-com-prod/packages/dotnet-runtime-2.2.6-x64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID be1229cf: NOKEY        ]  17 MB/s |  55 MB  00:00:07 ETA 
dotnet-runtime-2.2.6-x64.rpm 的公钥尚未安装
(1/5): dotnet-runtime-2.2.6-x64.rpm                                                                                                                                   |  27 MB  00:00:02     
(2/5): dotnet-runtime-deps-2.2.6-rhel.7-x64.rpm                                                                                                                       | 2.8 kB  00:00:00     
(3/5): libicu-50.1.2-17.el7.x86_64.rpm                                                                                                                                | 6.9 MB  00:00:01     
(4/5): aspnetcore-runtime-2.2.6-x64.rpm                                                                                                                               |  30 MB  00:00:17     
(5/5): dotnet-sdk-2.2.401-x64.rpm                                                                                                                                     | 116 MB  00:29:16     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                         105 kB/s | 180 MB  00:29:19     
从 https://packages.microsoft.com/keys/microsoft.asc 检索密钥
导入 GPG key 0xBE1229CF:
 用户ID     : "Microsoft (Release signing) "
 指纹       : bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf
 来自       : https://packages.microsoft.com/keys/microsoft.asc
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : libicu-50.1.2-17.el7.x86_64                                                                                                                                              1/7 
  正在安装    : dotnet-runtime-deps-2.2-2.2.6-1.x86_64                                                                                                                                   2/7 
  正在安装    : dotnet-host-2.2.6-1.x86_64                                                                                                                                               3/7 
  正在安装    : dotnet-hostfxr-2.2-2.2.6-1.x86_64                                                                                                                                        4/7 
  正在安装    : dotnet-runtime-2.2-2.2.6-1.x86_64                                                                                                                                        5/7 
  正在安装    : aspnetcore-runtime-2.2-2.2.6-1.x86_64                                                                                                                                    6/7 
  正在安装    : dotnet-sdk-2.2-2.2.401-1.x86_64                                                                                                                                          7/7 
This software may collect information about you and your use of the software, and send that to Microsoft.
Please visit http://aka.ms/dotnet-cli-eula for more information.
Welcome to .NET Core!
---------------------
Learn more about .NET Core: https://aka.ms/dotnet-docs
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs

Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous and doesn't include command-line arguments. The data is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

Configuring...
--------------
A command is running to populate your local package cache to improve restore speed and enable offline access. This command takes up to one minute to complete and only runs once.
  验证中      : dotnet-sdk-2.2-2.2.401-1.x86_64                                                                                                                                          1/7 
  验证中      : dotnet-host-2.2.6-1.x86_64                                                                                                                                               2/7 
  验证中      : aspnetcore-runtime-2.2-2.2.6-1.x86_64                                                                                                                                    3/7 
  验证中      : libicu-50.1.2-17.el7.x86_64                                                                                                                                              4/7 
  验证中      : dotnet-runtime-deps-2.2-2.2.6-1.x86_64                                                                                                                                   5/7 
  验证中      : dotnet-runtime-2.2-2.2.6-1.x86_64                                                                                                                                        6/7 
  验证中      : dotnet-hostfxr-2.2-2.2.6-1.x86_64                                                                                                                                        7/7 

已安装:
  dotnet-sdk-2.2.x86_64 0:2.2.401-1                                                                                                                                                          

作为依赖被安装:
  aspnetcore-runtime-2.2.x86_64 0:2.2.6-1  dotnet-host.x86_64 0:2.2.6-1  dotnet-hostfxr-2.2.x86_64 0:2.2.6-1  dotnet-runtime-2.2.x86_64 0:2.2.6-1  dotnet-runtime-deps-2.2.x86_64 0:2.2.6-1 
  libicu.x86_64 0:50.1.2-17.el7           

完毕!

2.4 测试dotnet命令:dotnet --version和dotnet --info

[root@localhost ~]# dotnet --version
2.2.401
[root@localhost ~]# dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.401
 Commit:    729b316c13

Runtime Environment:
 OS Name:     centos
 OS Version:  7
 OS Platform: Linux
 RID:         centos.7-x64
 Base Path:   /usr/share/dotnet/sdk/2.2.401/

Host (useful for support):
  Version: 2.2.6
  Commit:  7dac9b1b51

.NET Core SDKs installed:
  2.2.401 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

可见安装成功!

你可能感兴趣的:(.netcore)