在Ubuntu 18.04中安装.NetCore 3.1运行环境

权威的资料是微软官方的文档:在Ubuntu上安装.NET SDK或.NET运行时

1、准备工作

(1) 添加Microsoft包签名密钥

将Microsoft包签名密钥添加到受信任密钥列表,并添加包存储库。

> wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
> sudo dpkg -i packages-microsoft-prod.deb

(2) unable to resolve host address错误

执行上面命令,会出现unable to resolve host address错误。通过Xshell进入Ubuntu系统,使用root权限修改resolv.conf,添加Google DNS配置。

> su
> password
> cd /etc
> vi resolv.conf

在编辑页面添加下面配置:

nameserver 8.8.8.8 #google域名服务器
nameserver 8.8.4.4 #google域名服务器

然后退出编辑并保存:

> Esc
> :x

2、在Ubuntu中安装.NetCore环境

(1) 安装.netcore SDK

> sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-3.1

(2) 出现错误

执行上面命令会出现如下错误:

Couldn't create temporary file /tmp/apt.conf.sqqT47 for passing config to apt-key

这是因为找不到文件夹/tmp,解决方法是使用root创建/tmp文件夹,并对其赋权:

> cd /
> mkdir tmp
> chmod 777 /tmp

(3) 安装.netcore运行时

> sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y aspnetcore-runtime-3.1

3、运行.netcore app

使用下面命令运行.netcore app:

dotnet TestConsole.dll

运行.netcore app时可能会出现“Failed to create CoreCLR, HRESULT: 0x80004005”错误,重新创建并赋权/tmp文件夹即可。

posted @ 2021-04-01 11:51  xhubobo  阅读(1874)  评论(0编辑  收藏  举报