Linux 上 .NET Core 的必要條件Prerequisites for .NET Core on Linux

本文會說明在 Linux 開發 .NET Core 應用程式所需的相依性。This article shows the dependencies needed to develop .NET Core applications on Linux. 支援的 Linux 發行版本/版本和跟隨的相依性,適用於在 Linux 開發 .NET Core 應用程式的兩種方式:The supported Linux distributions/versions, and dependencies that follow apply to the two ways of developing .NET Core apps on Linux:

支援的 Linux 版本Supported Linux versions

.NET Core 2.0 將 Linux 視為單一作業系統。.NET Core 2.0 treats Linux as a single operating system. 針對每個支援的 Linux 發行版本與每種晶片架構,會有單一的 Linux 組建。There is a single Linux build (per chip architecture) for supported Linux distros.

下列 Linux 64 位元 (x86_64 or amd64) 發行版本/版本支援NET Core 2.x:NET Core 2.x is supported on the following Linux 64-bit (x86_64 or amd64) distributions/versions:

  • Red Hat Enterprise Linux 7Red Hat Enterprise Linux 7
  • CentOS 7CentOS 7
  • Oracle Linux 7Oracle Linux 7
  • Fedora 25, Fedora 26Fedora 25, Fedora 26
  • Debian 8.7 或更新的版本Debian 8.7 or later versions
  • Ubuntu 17.04, Ubuntu 16.04, Ubuntu 14.04Ubuntu 17.04, Ubuntu 16.04, Ubuntu 14.04
  • Linux Mint 18, Linux Mint 17Linux Mint 18, Linux Mint 17
  • openSUSE 42.2 或更新的版本openSUSE 42.2 or later versions
  • SUSE Enterprise Linux (SLES) 12 SP2 或更新的版本SUSE Enterprise Linux (SLES) 12 SP2 or later versions

如需 .NET Core 2.x 支援的作業系統完整清單、不支援的作業系統版本,以及週期原則連結,請參閱 .NET Core 2.x 支援的作業系統版本See .NET Core 2.x Supported OS Versions for the complete list of .NET Core 2.x supported operating systems, out of support OS versions, and lifecycle policy links.

Linux 發行版本相依性Linux distribution dependencies

下列被要作為範例。The following are intended to be examples. 確切的版本和名稱會有些許上您所選擇的 Linux 散發。The exact versions and names may vary slightly on your Linux distribution of choice.

UbuntuUbuntu

Ubuntu 發行版本需要安裝下列程式庫:Ubuntu distributions require the following libraries installed:

  • libunwind8libunwind8
  • liblttng ust0liblttng-ust0
  • libcurl3libcurl3
  • libssl1.0.0libssl1.0.0
  • libuuid1libuuid1
  • libkrb5libkrb5
  • zlib1gzlib1g
  • libicu52 (適用於 14.X)libicu52 (for 14.X)
  • libicu55 (適用於 16.X)libicu55 (for 16.X)
  • libicu57 (適用於 17.X)libicu57 (for 17.X)

CentOSCentOS

CentOS 發行版本需要安裝下列程式庫:CentOS distributions require the following libraries installed:

  • libunwindlibunwind
  • lttng ustlttng-ust
  • libcurllibcurl
  • openssl 程式庫openssl-libs
  • libuuidlibuuid
  • krb5 程式庫krb5-libs
  • libiculibicu
  • zlibzlib

如需有關相依性的詳細資訊,請參閱獨立式 Linux 應用程式 (英文)。For more information about the dependencies, see Self-contained Linux applications.

使用原生安裝程式來安裝 .NET Core 相依性Installing .NET Core dependencies with the native installers

受支援的 Linux 發行版本/版本可使用 .NET Core 原生安裝程式。.NET Core native installers are available for supported Linux distributions/versions. 原生安裝程式需要伺服器的管理員 (sudo) 存取權。The native installers require admin (sudo) access to the server. 使用原生安裝程式的優點在於它會安裝所有的 .NET Core 原生相依性。The advantage of using a native installer is that all of the .NET Core native dependencies are installed. 原生安裝程式也會安裝 .NET Core SDK 全系統。Native installers also install the .NET Core SDK system-wide.

Linux 上有兩個安裝程式套件選擇:On Linux, there are two installer package choices:

  • 使用摘要型套件管理員,例如 Ubuntu 的 apt get 或 CentOS/RHEL 的 yum。Using a feed-based package manager, such as apt-get for Ubuntu, or yum for CentOS/RHEL.
  • 使用套件本身,DEB 或 RPM。Using the packages themselves, DEB or RPM.

使用 .NET Core 安裝程式指令碼以指令碼進行安裝Scripting Installs with the .NET Core installer script

dotnet-install 指令碼用來執行 CLI 工具鏈和共用執行階段的非 Admin 安裝。The dotnet-install scripts are used to perform a non-admin install of the CLI toolchain and the shared runtime. 您可以下載從指令碼: https://dot.net/v1/dotnet-install.shYou can download the script from: https://dot.net/v1/dotnet-install.sh

安裝程式 bash 指令碼是用於自動化案例和非系統管理員安裝。The installer bash script is used in automation scenarios and non-admin installations. 此指令碼也能讀取 PowerShell 參數,所以它們可以搭配 Linux/OS X 系統上的指令碼一起使用。This script also reads PowerShell switches, so they can be used with the script on Linux/OS X systems.

重要

執行指令碼之前,請安裝所有必要的相依性 (英文)Before running the script, install the required dependencies.

安裝 Red Hat Enterprise Linux (RHEL) 7 的 .NET CoreInstall .NET Core for Red Hat Enterprise Linux (RHEL) 7

若要在 RHEL 7 上安裝 .NET Core:To install .NET Core on RHEL 7:

  1. 啟用 Red Hat .NET 通道,位於 RHEL 7 訂閱底下。Enable the Red Hat .NET channel, available under your RHEL 7 subscription.

    • Red Hat Enterprise 7 伺服器請使用:For Red Hat Enterprise 7 Server, use:

      subscription-manager repos --enable=rhel-7-server-dotnet-rpms
      
    • Red Hat Enterprise 7 工作站請使用:For Red Hat Enterprise 7 Workstation, use:

      subscription-manager repos --enable=rhel-7-workstation-dotnet-rpms
      
    • Red Hat Enterprise 7 HPC 計算節點請使用:For Red Hat Enterprise 7 HPC Compute Node, use:

      subscription-manager repos --enable=rhel-7-hpc-node-dotnet-rpms
      
  2. 安裝 scl 工具。Install the scl tool.

    yum install scl-utils
    
  3. 安裝 .NET CoreInstall .NET Core

安裝 .NET Core 2.0 SDK 及執行階段:Install .NET Core 2.0 SDK and Runtime:

yum install rh-dotnet20

為環境啟用 .NET Core 2.0 SDK/執行階段:Enable .NET Core 2.0 SDK/Runtime for your environment:

scl enable rh-dotnet20 bash
  1. 執行 dotnet --version 命令,以證明安裝成功。Run the dotnet --version command to prove the installation succeeded.

    dotnet --version
    

如需 Red Hat .NET 通道存取登錄說明,請參閱 Red Hat 的 .NET Core 1.1 入門指南的第 1 章For Red Hat .NET channel access registration help, see Chapter 1 of the .NET Core 1.1 Getting Started Guide at Red Hat.

安裝適用於 Ubuntu 14.04, Ubuntu 16.04, Ubuntu 16.10 與 Linux Mint 17, Linux Mint 18 的 .NET Core (64 位元)Install .NET Core for Ubuntu 14.04, Ubuntu 16.04, Ubuntu 16.10 & Linux Mint 17, Linux Mint 18 (64 bit)

  1. 請移除系統中所有 .NET Core 先前的預覽版Remove any previous preview versions of .NET Core from your system.
  1. 註冊受信任的 Microsoft 產品金鑰。Register the Microsoft Product key as trusted.

    curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
    sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
    
  2. 設定所需的裝載套件摘要版本。Set up the desired version host package feed.

    Ubuntu 17.04Ubuntu 17.04

    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-zesty-prod zesty main" > /etc/apt/sources.list.d/dotnetdev.list'
    sudo apt-get update
    

    Ubuntu 16.04 / Linux Mint 18Ubuntu 16.04 / Linux Mint 18

    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
    sudo apt-get update
    

    Ubuntu 14.04 / Linux Mint 17Ubuntu 14.04 / Linux Mint 17

    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
    sudo apt-get update
    
  3. 安裝 .NET Core。Install .NET Core.

    sudo apt-get install dotnet-sdk-2.0.0
    
  4. 執行 dotnet --version 命令,以證明安裝成功。Run the dotnet --version command to prove the installation succeeded.

    dotnet --version
    

安裝適用於 Debian 8 或 Debian 9 的 .NET Core (64 位元)Install .NET Core for Debian 8 or Debian 9 (64 bit)

若要在 Debian 8 或 Debian 9 上安裝 .NET Core (64 位元):To install .NET Core on Debian 8 or Debian 9 (64 bit):

  1. 請移除系統中所有 .NET Core 先前的預覽版Remove any previous preview versions of .NET Core from your system.

注意

需要使用者控制的目錄,以用於來自 tar.gz 的 Linux 系統安裝。A user-controlled directory is required for Linux system installs from tar.gz.

  1. 安裝系統元件。Install system components.

    sudo apt-get update
    sudo apt-get install curl libunwind8 gettext apt-transport-https
    
  2. 註冊受信任的 Microsoft 產品金鑰。Register the trusted Microsoft Product key.

    curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
    sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
    
  3. 註冊 Microsoft 產品摘要。Register the Microsoft Product feed.

    Debian 9 (Stretch)Debian 9 (Stretch)

    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list'
    

    Debian 8 (Jessie)Debian 8 (Jessie)

    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/dotnetdev.list'
    
  4. 安裝 .NET Core SDK。Install .NET Core SDK.

    sudo apt-get update
    sudo apt-get install dotnet-sdk-2.0.0
    
  5. 將 dotnet 新增至 PATH。Add dotnet to your PATH.

    export PATH=$PATH:$HOME/dotnet
    
  6. 執行 dotnet --version 命令,以證明安裝成功。Run the dotnet --version command to prove the installation succeeded.

    dotnet --version
    

安裝適用於 Fedora 24, Fedora 25 或 Fedora 26 的 .NET Core (64 位元)Install .NET Core for Fedora 24, Fedora 25, or Fedora 26 (64 bit)

在 Fedora 26 或 Fedora 25 上安裝 .NET Core 2.x,或在 Fedora 24 上安裝 .NET Core 1.x:To install .NET Core 2.x on Fedora 26 or Fedora 25, or .NET Core 1.x on Fedora 24:

  1. 請移除系統中所有 .NET Core 先前的預覽版Remove any previous preview versions of .NET Core from your system.

注意

需要使用者控制的目錄,以用於來自 tar.gz 的 Linux 系統安裝。A user-controlled directory is required for Linux system installs from tar.gz.

Fedora 26 或 Fedora 25Fedora 26 or Fedora 25

  1. 註冊 Microsoft 簽章金鑰。Register the Microsoft signature key.

    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
  2. 新增 dotnet 產品摘要。Add the dotnet product feed.

    sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo'
    
  3. 安裝 .NET Core SDK。Install the .NET Core SDK.

    sudo dnf update
    sudo dnf install libunwind libicu
    sudo dnf install dotnet-sdk-2.0.0
    
  4. 將 dotnet 新增至 PATH。Add dotnet to your PATH.

    export PATH=$PATH:$HOME/dotnet
    
  1. 執行 dotnet --version 命令,以證明安裝成功。Run the dotnet --version command to prove the installation succeeded.

    dotnet --version
    

安裝 .NET Core for CentOS 7.1 (64 位元) 以及 Oracle Linux 7.1 (64 位元)Install .NET Core for CentOS 7.1 (64 bit) & Oracle Linux 7.1 (64 bit)

安裝 .NET Core for CentOS 7.1 (64 位元) 與 Oracle Linux 7.1 (64 位元):To install .NET Core for CentOS 7.1 (64 bit) & Oracle Linux 7.1 (64 bit):

  1. 請移除系統中所有 .NET Core 先前的預覽版Remove any previous preview versions of .NET Core from your system.

注意

需要使用者控制的目錄,以用於來自 tar.gz 的 Linux 系統安裝。A user-controlled directory is required for Linux system installs from tar.gz.

  1. 註冊 Microsoft 簽章金鑰。Register the Microsoft signature key.

    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
  2. 新增 Microsoft 產品摘要。Add the Microsoft Product feed.

    sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo'
    
  3. 安裝 .NET Core SDK。Install the .NET Core SDK.

    sudo yum update
    sudo yum install libunwind libicu
    sudo yum install dotnet-sdk-2.0.0
    
  4. 將 dotnet 新增至 PATHAdd dotnet to your PATH

    export PATH=$PATH:$HOME/dotnet
    
  1. 執行 dotnet --version 命令,以證明安裝成功。Run the dotnet --version command to prove the installation succeeded.

    dotnet --version
    

安裝適用於 SUSE Linux Enterprise Server 的 .NET Core (64 位元)Install .NET Core for SUSE Linux Enterprise Server (64 bit)

安裝適用於 SUSE Linux Enterprise Server (SLES) 12 SP2 (64 位元) 的 .NET Core 2.x:To install .NET Core 2.x for SUSE Linux Enterprise Server (SLES) 12 SP2 (64 bit):

  1. 請移除系統中所有 .NET Core 先前的預覽版Remove any previous preview versions of .NET Core from your system.

  2. 新增 dotnet 產品摘要。Add the dotnet product feed.

    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/dotnetdev.repo'
    
  3. 安裝 .NET Core SDK。Install the .NET Core SDK.

    sudo zypper update
    sudo zypper install libunwind libicu
    sudo zypper install dotnet-sdk-2.0.0
    
  4. 將 dotnet 新增至 PATH。Add dotnet to your PATH.

    export PATH=$PATH:$HOME/dotnet
    
  5. 執行 dotnet --version 命令,以證明安裝成功。Run the dotnet --version command to prove the installation succeeded.

    dotnet --version
    

安裝適用於 openSUSE 的 .NET Core (64 位元)Install .NET Core for openSUSE (64 bit)

安裝適用於 openSUSE 的 .NET Core 2.x 或適用於 openSUSE (64 位元) 的 .NET Core 1.x:To install .NET Core 2.x for openSUSE or .NET Core 1.x for openSUSE (64 bit):

  1. 請移除系統中所有 .NET Core 先前的預覽版Remove any previous preview versions of .NET Core from your system.

注意

需要使用者控制的目錄,以用於來自 tar.gz 的 Linux 系統安裝。A user-controlled directory is required for Linux system installs from tar.gz.

  1. 註冊 Microsoft 簽章金鑰。Register the Microsoft signature key.

    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
  2. 新增 dotnet 產品摘要。Add the dotnet product feed.

    sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/dotnetdev.repo'
    
  3. 安裝 .NET Core SDK。Install the .NET Core SDK.

    sudo zypper update
    sudo zypper install libunwind libicu
    sudo zypper install dotnet-sdk-2.0.0
    
  4. 將 dotnet 新增至 PATH。Add dotnet to your PATH.

    export PATH=$PATH:$HOME/dotnet
    
  1. 執行 dotnet --version 命令,以證明安裝成功。Run the dotnet --version command to prove the installation succeeded.

    dotnet --version
    

重要

如果支援的 Linux 發行版本/版本遇到 .NET Core 2.x 安裝問題,請參閱已安裝的發行版本/版本的 2.0 已知問題主題。If you have problems with the .NET Core 2.x installation on a supported Linux distribution/version, consult the 2.0 Known issues topic for your installed distributions/versions.

如果支援的 Linux 發行版本/版本遇到 .NET Core 1.x 安裝問題,請參閱已安裝的發行版本/版本的 1.0.0 已知問題1.0.1 已知問題主題。If you have problems with the .NET Core 1.x installation on a supported Linux distribution/version, consult the 1.0.0 Known Issues and 1.0.1 Known Issues topics for your installed distributions/versions.