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"

摘抄

擴展


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM