Linux 安裝 powershell


linux 安裝 powershell

Intro

powershell 已經推出了一個 Powershell Core, 版本號對應 Powershell 6.x,可以跨平台,支持 Linux 和 mac.
這使得對於熟練使用 Powershell 進行開發運維的一些開發者來說無疑是個福音。

今天就來在 Linux 上安裝 powershell,以 centos7 為例介紹安裝 powershell。

PowerShell 和 PowerShell Core

那Windows PowerShell與PowerShell Core 6.0又有什么區別呢,主要幾個區別如下:

  • Windows PowerShell是基於.NET Framework的,所以它也只能在Windows中使用。
    PowerShell Core 6.0發布時,Windows PowerShell 最新的版本在5.*,但PowerShell Core 6.0 可不是Windows PowerShell的升級版本。
  • PowerShell Core 6.0因為它的跨平台,自然不僅可以在 Windows 上運行也可以在其它平台如macOS與Linux上運行,因為它是基於.NET Core基礎之上的。
  • Windows PowerShell在 Windows 中的執行文件為powershell.exe,而PowerShell Core 6.0在Windows中的執行文件是pwsh.exe,在 macOS 和 Linux 中的執行文件是 pwsh

PowerShell Core 平台支持情況

PowerShell 現在官方支持 macOS 和 Linux,包括:

  • Windows 7、8.1 和 10
  • Windows Server 2008 R2、2012 R2、2016
  • Windows Server 半年頻道
  • Ubuntu 14.04、16.04 和 17.04
  • Debian 8.7+ 和 9
  • CentOS 7
  • Red Hat Enterprise Linux 7
  • OpenSUSE 42.2
  • Fedora 25、26
  • macOS 10.12+

我們社區也為以下平台提供包,但是它們不受正式支持:

  • Arch Linux
  • Kali Linux
  • AppImage(可在多個 Linux 平台上運行)

我們還對以下平台提供試驗版本(不受支持):

  • ARM32/ARM64 上的 Windows
  • Raspbian (Stretch)

在 Linux上安裝 PowerShell

這里以 Centos 為例,介紹如何安裝 PowerShell,其他 Linux 系統可以參考這里的文檔

這里有兩種方式可以安裝

  • 注冊微軟的鏡像源(推薦)

    # Register the Microsoft RedHat repository
    curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
    
    # Install PowerShell
    sudo yum install -y powershell
    
    
  • 直接下載文件安裝

    sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v6.1.0/powershell-6.1.0-1.rhel.7.x86_64.rpm
    

安裝完成之后可以直接執行 pwsh 就可以進入 powershell 了,如果可以正常進入則證明安裝成功了。

卸載

sudo yum remove powershell

Reference

Contact

Contact me: weihanli@outlook.com


免責聲明!

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



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