mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-25 00:50:15 +08:00
翻译完成
This commit is contained in:
parent
e5b3c1c6a0
commit
6017c1a9b3
@ -7,20 +7,20 @@
|
|||||||
[#]: via: (https://www.ostechnix.com/how-to-install-microsoft-net-core-sdk-on-linux/)
|
[#]: via: (https://www.ostechnix.com/how-to-install-microsoft-net-core-sdk-on-linux/)
|
||||||
[#]: author: (SK https://www.ostechnix.com/author/sk/)
|
[#]: author: (SK https://www.ostechnix.com/author/sk/)
|
||||||
|
|
||||||
How To Install Microsoft .NET Core SDK On Linux
|
如何在 Linux 中安装微软的 .NET Core SDK
|
||||||
======
|
======
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
The **.NET Core** is a free, cross platform and open source framework developed by Microsoft to build desktop applications, mobile apps, web apps, IoT apps and gaming apps etc. If you’re dotnet developer coming from Windows platform, .NET core helps you to setup your development environment easily on any Linux and Unix-like operating systems. This step by step guide explains how to install Microsoft .NET Core SDK on Linux and how to write your first app using .Net.
|
**.NET Core** 是微软提供的免费、跨平台和开源的开发框架,可以构建桌面应用程序、移动端应用程序、网络应用程序、物联网应用程序和游戏应用程序等。如果你是 Windows 平台下的 dotnet 开发人员的话,使用 .NET core 可以很轻松就设置好任何 Linux 和类 Unix 操作系统下的开发环境。本分步操作指南文章解释了如何在 Linux 中安装 .NET Core SDK 以及如何使用 .NET 开发出第一个应用程序。
|
||||||
|
|
||||||
### Install Microsoft .NET Core SDK On Linux
|
### Linux 中安装 .NET Core SDK
|
||||||
|
|
||||||
The .NET core supports GNU/Linux, Mac OS and Windows. .Net core can be installed on popular GNU/Linux operating systems including Debian, Fedora, CentOS, Oracle Linux, RHEL, SUSE/openSUSE, and Ubuntu. As of writing this guide, the latest .NET core version was **2.2**.
|
.NET Core 支持 GNU/Linux、Mac OS 和 Windows 系统,可以在主流的 GNU/Linux 操作系统上安装运行,包括 Debian、Fedora、CentOS、Oracle Linux、RHEL、SUSE/openSUSE 和 Ubuntu 。在撰写这篇教程时,其最新版本为 **2.2**。
|
||||||
|
|
||||||
On **Debian 9** , you can install .NET Core SDK as shown below.
|
**Debian 9** 系统上安装 .NET Core SDK,请按如下步骤进行。
|
||||||
|
|
||||||
First of all, you need to register Microsoft key and add .NET repository by running the following commands:
|
首先,需要注册微软的密钥,接着把 .NET 源仓库地址添加进来,运行的命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
|
$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
|
||||||
@ -31,16 +31,16 @@ $ sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
|
|||||||
$ sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
|
$ sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
|
||||||
```
|
```
|
||||||
|
|
||||||
After registering the key and adding the repository, install .NET SDK using commands:
|
注册好密钥及添加完仓库源后,就可以安装 .NET SDK 了,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo apt-get update
|
$ sudo apt-get update
|
||||||
$ sudo apt-get install dotnet-sdk-2.2
|
$ sudo apt-get install dotnet-sdk-2.2
|
||||||
```
|
```
|
||||||
|
|
||||||
**On Debian 8:**
|
**Debian 8 系统上安装:**
|
||||||
|
|
||||||
Add Microsoft key and enable .NET repository:
|
增加微软密钥,添加 .NET 仓库源:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
|
$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
|
||||||
@ -51,16 +51,16 @@ $ sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
|
|||||||
$ sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
|
$ sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
|
||||||
```
|
```
|
||||||
|
|
||||||
Install .NET SDK:
|
安装 .NET SDK:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo apt-get update
|
$ sudo apt-get update
|
||||||
$ sudo apt-get install dotnet-sdk-2.2
|
$ sudo apt-get install dotnet-sdk-2.2
|
||||||
```
|
```
|
||||||
|
|
||||||
**On Fedora 28:**
|
**Fedora 28 系统上安装:**
|
||||||
|
|
||||||
Add Microsoft key and enable .NET repository:
|
增加微软密钥,添加 .NET 仓库源:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
|
$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
|
||||||
@ -69,14 +69,16 @@ $ sudo mv prod.repo /etc/yum.repos.d/microsoft-prod.repo
|
|||||||
$ sudo chown root:root /etc/yum.repos.d/microsoft-prod.repo
|
$ sudo chown root:root /etc/yum.repos.d/microsoft-prod.repo
|
||||||
```
|
```
|
||||||
|
|
||||||
Now, Install .NET SDK:
|
现在, 可以安装 .NET SDK 了:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo dnf update
|
$ sudo dnf update
|
||||||
$ sudo dnf install dotnet-sdk-2.2
|
$ sudo dnf install dotnet-sdk-2.2
|
||||||
```
|
```
|
||||||
|
|
||||||
On **Fedora 27** , add the key and repository using commands:
|
**Fedora 27 系统下:**
|
||||||
|
|
||||||
|
增加微软密钥,添加 .NET 仓库源,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
|
$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
|
||||||
@ -85,31 +87,31 @@ $ sudo mv prod.repo /etc/yum.repos.d/microsoft-prod.repo
|
|||||||
$ sudo chown root:root /etc/yum.repos.d/microsoft-prod.repo
|
$ sudo chown root:root /etc/yum.repos.d/microsoft-prod.repo
|
||||||
```
|
```
|
||||||
|
|
||||||
And install .NET SDK using commands:
|
接着安装 .NET SDK ,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo dnf update
|
$ sudo dnf update
|
||||||
$ sudo dnf install dotnet-sdk-2.2
|
$ sudo dnf install dotnet-sdk-2.2
|
||||||
```
|
```
|
||||||
|
|
||||||
**On CentOS/Oracle Linux:**
|
**CentOS/Oracle 版本的 Linux 系统上:**
|
||||||
|
|
||||||
Add Microsoft key and enable .NET core repository:
|
增加微软密钥,添加 .NET 仓库源,使其可用
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
|
$ sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
|
||||||
```
|
```
|
||||||
|
|
||||||
Update the repositories and install .NET SDK:
|
更新源仓库,安装 .NET SDK:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo yum update
|
$ sudo yum update
|
||||||
$ sudo yum install dotnet-sdk-2.2
|
$ sudo yum install dotnet-sdk-2.2
|
||||||
```
|
```
|
||||||
|
|
||||||
**On openSUSE Leap:**
|
**openSUSE Leap 版本的系统上:**
|
||||||
|
|
||||||
Add key, enable repository and install necessary dependencies using the following commands:
|
添加密钥,使仓库源可用,安装必需的依赖包,其命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo zypper install libicu
|
$ sudo zypper install libicu
|
||||||
@ -119,29 +121,29 @@ $ sudo mv prod.repo /etc/zypp/repos.d/microsoft-prod.repo
|
|||||||
$ sudo chown root:root /etc/zypp/repos.d/microsoft-prod.repo
|
$ sudo chown root:root /etc/zypp/repos.d/microsoft-prod.repo
|
||||||
```
|
```
|
||||||
|
|
||||||
Update the repositories and Install .NET SDK using commands:
|
更新源仓库,安装 .NET SDK,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo zypper update
|
$ sudo zypper update
|
||||||
$ sudo zypper install dotnet-sdk-2.2
|
$ sudo zypper install dotnet-sdk-2.2
|
||||||
```
|
```
|
||||||
|
|
||||||
**On Ubuntu 18.04 LTS:**
|
**Ubuntu 18.04 LTS 版本的系统上:**
|
||||||
|
|
||||||
Register the Microsoft key and .NET core repository using commands:
|
注册微软的密钥和 .NET Core 仓库源,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
|
$ wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
|
||||||
$ sudo dpkg -i packages-microsoft-prod.deb
|
$ sudo dpkg -i packages-microsoft-prod.deb
|
||||||
```
|
```
|
||||||
|
|
||||||
Enable ‘Universe’ repository using:
|
使 ‘Universe’ 仓库可用:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo add-apt-repository universe
|
$ sudo add-apt-repository universe
|
||||||
```
|
```
|
||||||
|
|
||||||
Then, install .NET Core SDK using command:
|
然后,安装 .NET Core SDK ,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo apt-get install apt-transport-https
|
$ sudo apt-get install apt-transport-https
|
||||||
@ -149,16 +151,16 @@ $sudo apt-get update
|
|||||||
$ sudo apt-get install dotnet-sdk-2.2
|
$ sudo apt-get install dotnet-sdk-2.2
|
||||||
```
|
```
|
||||||
|
|
||||||
**On Ubuntu 16.04 LTS:**
|
**Ubuntu 16.04 LTS 版本的系统上:**
|
||||||
|
|
||||||
Register Microsoft key and .NET repository using commands:
|
注册微软的密钥和 .NET Core 仓库源,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
|
$ wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
|
||||||
$ sudo dpkg -i packages-microsoft-prod.deb
|
$ sudo dpkg -i packages-microsoft-prod.deb
|
||||||
```
|
```
|
||||||
|
|
||||||
And then, Install .NET core SDK:
|
然后安装 .NET core SDK:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo apt-get install apt-transport-https
|
$ sudo apt-get install apt-transport-https
|
||||||
@ -166,17 +168,17 @@ $ sudo apt-get update
|
|||||||
$ sudo apt-get install dotnet-sdk-2.2
|
$ sudo apt-get install dotnet-sdk-2.2
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create Your First App
|
### 创建你的第一个应用程序
|
||||||
|
|
||||||
We have successfully installed .Net Core SDK in our Linux box. It is time to create our first app using dotnet.
|
我们已经成功的在 Linux 机器中安装了 .NET Core SDK。是时候使用 dotnet 创建第一个应用程序了。
|
||||||
|
|
||||||
For the purpose of this guide, I am going to create a new app called **“ostechnixApp”**. To do so, simply run the following command:
|
接下来的目的,我们会创建一个名为 **“ostechnixApp”** 的应用程序。为此,可以简单的运行如下命令:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ dotnet new console -o ostechnixApp
|
$ dotnet new console -o ostechnixApp
|
||||||
```
|
```
|
||||||
|
|
||||||
**Sample output:**
|
**简单的输出:**
|
||||||
|
|
||||||
```
|
```
|
||||||
Welcome to .NET Core!
|
Welcome to .NET Core!
|
||||||
@ -208,9 +210,9 @@ Restore completed in 894.27 ms for /home/sk/ostechnixApp/ostechnixApp.csproj.
|
|||||||
Restore succeeded.
|
Restore succeeded.
|
||||||
```
|
```
|
||||||
|
|
||||||
As you can see in the above output, .Net has created a new application of type console. The parameter -o creates a directory named “ostechnixApp” where you store your app data with all necessary files.
|
正如上面的输出所示的,.NET 已经为我们创建一个控制台类型的应用程序。`-o` 参数创建了一个名为 “ostechnixApp” 的目录,其包含有存储此应用程序数据所必需的文件。
|
||||||
|
|
||||||
Let us switch to ostechnixApp directory and see what’s in there.
|
让我们切换到 ostechnixApp 目录,看看里面有些什么。
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cd ostechnixApp/
|
$ cd ostechnixApp/
|
||||||
@ -218,7 +220,7 @@ $ ls
|
|||||||
obj ostechnixApp.csproj Program.cs
|
obj ostechnixApp.csproj Program.cs
|
||||||
```
|
```
|
||||||
|
|
||||||
As you there are three files named **ostechnixApp.csproj** and **Program.cs** and one directory named **obj**. By default, the Program.cs file will contain the code to run the ‘Hello World’ program in the console. Let us have a look at the code.
|
可以看到有两个名为 **ostechnixApp.csproj** 和 **Program.cs** 的文件,以及一个名为 **ojb** 的目录。默认情况下, `Program.cs` 文件包含有可以在控制台中运行的 'Hello World' 程序代码。可以看看此代码:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cat Program.cs
|
$ cat Program.cs
|
||||||
@ -236,7 +238,7 @@ namespace ostechnixApp
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
To run the newly created app, simply run the following command:
|
要运行此应用程序,可以简单的使用如下命令:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ dotnet run
|
$ dotnet run
|
||||||
@ -245,9 +247,9 @@ Hello World!
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Simple, isn’t it? Yes, it is! Now, you can write your code in the **Program.cs** file and run it as shown above.
|
很简单,对吧?是的,就是如此简单。现在你可以在 **Program.cs** 这文件中写上自己的代码,然后像上面所示的执行。
|
||||||
|
|
||||||
Alternatively, you can create a new directory, for example mycode, using commands:
|
或者,你可以创建一个新的目录,如例子所示的 `mycode` 目录,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ mkdir ~/.mycode
|
$ mkdir ~/.mycode
|
||||||
@ -255,13 +257,13 @@ $ mkdir ~/.mycode
|
|||||||
$ cd mycode/
|
$ cd mycode/
|
||||||
```
|
```
|
||||||
|
|
||||||
…and make that as your new development environment by running the following command:
|
然后运行如下命令,使其成为你的新开发环境目录:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ dotnet new console
|
$ dotnet new console
|
||||||
```
|
```
|
||||||
|
|
||||||
Sample output:
|
简单的输出:
|
||||||
|
|
||||||
```
|
```
|
||||||
The template "Console Application" was created successfully.
|
The template "Console Application" was created successfully.
|
||||||
@ -276,46 +278,46 @@ Restore completed in 331.87 ms for /home/sk/mycode/mycode.csproj.
|
|||||||
Restore succeeded.
|
Restore succeeded.
|
||||||
```
|
```
|
||||||
|
|
||||||
The above command will create two files named **mycode.csproj** and **Program.cs** and one directory named **obj**. Open the Program.cs file in your favorite editor, delete or modify the existing ‘hello world’ code with your own code.
|
上的命令会创建两个名叫 **mycode.csproj** 和 **Program.cs** 的文件及一个名为 **obj** 的目录。用你喜欢的编辑器打开 `Program.cs` 文件, 删除或修改原来的 'hello world' 代码段,然后编写自己的代码。
|
||||||
|
|
||||||
Once the code is written, save and close the Program.cs file and run the app using command:
|
写完代码,保存,关闭 Program.cs 文件,然后运行此应用程序,命令如下:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ dotnet run
|
$ dotnet run
|
||||||
```
|
```
|
||||||
|
|
||||||
To check the installed .NET core SDK version, simply run:
|
想要查看安装的 .NET core SDK 的版本的话,可以简单的运行:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ dotnet --version
|
$ dotnet --version
|
||||||
2.2.101
|
2.2.101
|
||||||
```
|
```
|
||||||
|
|
||||||
To get help, run:
|
要获得帮助,请运行:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ dotnet --help
|
$ dotnet --help
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get Microsoft Visual Studio Code Editor
|
### 使用微软的 Visual Studio Code 编辑器
|
||||||
|
|
||||||
To write the code, you can use your favorite editors of your choice. Microsoft has also its own editor named “ **Microsoft Visual Studio Code** ” with support for .NET. It is an open source, lightweight and powerful source code editor. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Python, PHP, Go) and runtimes (such as .NET and Unity). It is a cross-platform code editor, so you can use it in Microsoft Windows, GNU/Linux, and Mac OS X. You can use it if you’re interested.
|
要编写代码,你可以任选自己喜欢的编辑器。同时微软自己也有一款支持 .NET 的编辑器,其名为 “ **Microsoft Visual Studio Code** ”。它是一款开源、轻量级、功能强大的源代码编辑器。其内置了对 JavaScript、TypeScript 和 Node.js 的支持,并为其它语言(如 C++、C#、Python、PHP、Go)和运行时态(如 .NET 和 Unity)提供了丰富的扩展,已经形成一个完整的生态系统。它是一款跨平台的代码编辑器,所以在微软的 Windows 系统、GNU/Linux 系统和 Mac OS X 系统都可以使用。如果对其感兴趣,就可以使用。
|
||||||
|
|
||||||
To know how to install and use it on Linux, please refer the following guide.
|
To know how to install and use it on Linux, please refer the following guide.想了解如何在 Linux 上安装和使用,请参阅以下指南。
|
||||||
|
|
||||||
[Install Microsoft Visual Studio Code In Linux][3]
|
[Linux 中安装 Microsoft Visual Studio Code][3]
|
||||||
|
|
||||||
[**This page**][1] has some basic tutorials to learn .NET Core and .NET Core SDK tools using Visual Studio Code editor. Go and check them to learn more.
|
关于 Visual Studio Code editor 中 .NET Core 和 .NET Core SDK 工具的使用,[**此网页**][1]有一些基础的教程。想了解更多就去看看吧。
|
||||||
|
|
||||||
### Telemetry
|
### Telemetry
|
||||||
|
|
||||||
By default, the .NET core SDK will collect the usage data using a feature called **‘Telemetry’**. The collected data is anonymous and shared to the development team and community under the [Creative Commons Attribution License][2]. So the .NET team will understand how the tools are used and decide how they can be improved over time. If you don’t want to share your usage information, you can simply opt-out of telemetry by setting the **DOTNET_CLI_TELEMETRY_OPTOUT** environment variable to **‘1’** or **‘true’** using your favorite shell.
|
默认情况下,.NET core SDK 会采集用户使用情况数据,此功能被称为 **‘Telemetry’**。采集数据是匿名的,并根据[知识共享署名许可][2]分享给其开发团队和社区。因此 .NET 团队会知道这些工具的使用状况,然后根据统计做出决策,改进产品。如果你不想分享自己的使用信息的话,可以使用顺手的 shell 工具把名为 **DOTNET_CLI_TELEMETRY_OPTOUT** 的环境变量参数设置为 **‘1’** 或 **‘true’**,这样就简单的关闭此功能了。
|
||||||
|
|
||||||
And, that’s all. You know how to install .NET Core SDK on various Linux platforms and how to create a basic app using it. TO learn more about .NET usage, refer the links given at the end of this guide.
|
就这样。你已经知道如何在各 Linux 平台上安装 .NET Core SDK 以及知道如何创建基本的应用程序了。想了解更多 .NET 使用知识的话,请参阅此文章末尾给出的链接。
|
||||||
|
|
||||||
More good stuffs to come. Stay tuned!
|
会爆出更多干货的。敬请关注!
|
||||||
|
|
||||||
Cheers!
|
祝贺下!
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user