Share via


在 Debian 上安裝 PowerShell

所有套件都可在我們的 GitHub 版本 頁面上取得。 安裝之前,請先檢查下方支援的版本清單。 安裝套件之後,請從終端機執行 pwsh 。 如果您已安裝預覽版本,請執行 pwsh-lts

注意

PowerShell 7.4 是移除舊版 PowerShell 7 的就地升級。 PowerShell 的預覽版本可以與其他 PowerShell 版本並存安裝。 如果您需要與舊版並存執行 PowerShell 7.4,請使用 二進位封存 方法重新安裝舊版。

Debian 使用 APT (進階套件工具) 作為套件管理員。

透過套件存放庫在 Debian 10 或 11 上安裝

Microsoft 為 Linux 系統建置並支援各種軟體產品,並透過 Linux 封裝用戶端提供它們(apt、dnf、yum 等)。 這些 Linux 軟體套件裝載於 Microsoft 產品的 Linux 套件存放庫上https://packages.microsoft.com也稱為 PMC

從 PMC 安裝 PowerShell 是慣用的安裝方法。

注意

此腳本僅適用於支援的 Debian 版本。

###################################
# Prerequisites

# Update the list of packages
sudo apt-get update

# Install pre-requisite packages.
sudo apt-get install -y wget

# Get the version of Debian
source /etc/os-release

# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/debian/$VERSION_ID/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Delete the Microsoft repository GPG keys file
rm packages-microsoft-prod.deb

# Update the list of packages after we added packages.microsoft.com
sudo apt-get update

###################################
# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

透過直接下載安裝

PowerShell 7.2 引進了通用套件,讓安裝更容易。 將通用套件從 發行 頁面下載到您的 Debian 電腦。

目前版本的連結如下:

  • 支援 Debian 版本的 PowerShell 7.4 (LTS) 通用套件
    • https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/powershell_7.4.2-1.deb_amd64.deb
  • 支援 Debian 版本的 PowerShell 7.2 (LTS) 通用套件
    • https://github.com/PowerShell/PowerShell/releases/download/v7.2.19/powershell_7.2.19-1.deb_amd64.deb
  • 支援Debian版本的PowerShell 7.5預覽通用套件
    • https://github.com/PowerShell/PowerShell/releases/download/v7.5.0-preview.2/powershell-preview_7.5.0-preview.2-1.deb_amd64.deb

下列殼層腳本會下載並安裝目前的PowerShell版本。 您可以變更 URL 以下載您要安裝的 PowerShell 版本。

###################################
# Prerequisites

# Update the list of packages
sudo apt-get update

# Install pre-requisite packages.
sudo apt-get install -y wget

# Download the PowerShell package file
wget https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/powershell_7.4.2-1.deb_amd64.deb

###################################
# Install the PowerShell package
sudo dpkg -i powershell_7.4.2-1.deb_amd64.deb

# Resolve missing dependencies and finish the install (if necessary)
sudo apt-get install -f

# Delete the downloaded package file
rm powershell_7.4.2-1.deb_amd64.deb

# Start PowerShell
pwsh

卸載 PowerShell

sudo apt-get remove powershell

PowerShell 路徑

  • $PSHOME/opt/microsoft/powershell/7/
  • 設定檔案文稿會儲存在下列位置:
    • AllUsersAllHosts - $PSHOME/profile.ps1
    • AllUsersCurrentHost - $PSHOME/Microsoft.PowerShell_profile.ps1
    • CurrentUserAllHosts - ~/.config/powershell/profile.ps1
    • CurrentUserCurrentHost - ~/.config/powershell/Microsoft.PowerShell_profile.ps1
  • 模組會儲存在下列位置:
    • 使用者模組 - ~/.local/share/powershell/Modules
    • 共用模組 - /usr/local/share/powershell/Modules
    • 預設模組 - $PSHOME/Modules
  • PSReadLine 歷程記錄會記錄於 ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt

PowerShell 遵循 Linux 上的 XDG 基底目錄規格

支援的版本

Microsoft 支援 PowerShell,直到 PowerShell 達到終止支援 或 Debian 版本 達到生命週期結束為止。

Debian 11 (Bullseye) - OS 支援將於 2024-07-31 結束

  • 您可以從 Microsoft 成品登錄 取得包含 PowerShell 7.2、PowerShell 7.4 和 PowerShell 7.5-preview for x64 的 Docker 映射

Debian 12 (Bookworm) - OS 支持終止於 2026-06-10

  • 您可以從 Microsoft 成品登錄 取得包含 PowerShell 7.2、PowerShell 7.4 和 PowerShell 7.5-preview for x64 的 Docker 映射

PowerShell 的預覽版本僅供測試和意見反應使用。

安裝支援

Microsoft 支援本檔中的安裝方法。 可能還有其他第三方來源可用的安裝方法。 雖然這些工具和方法可能正常運作,但 Microsoft 無法支援這些方法。