微軟剛剛開源了PowerShell,目前在Linux和MacOS上都能安裝。具體的連結如下:
https://github.com/PowerShell/PowerShell
本文將介紹如何在CentOS 7.2下安裝PowerShell。
首先在CentOS下下載PowerShell的安裝包:
wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm 或者: wget https://hweast.blob.core.chinacloudapi.cn/soft/powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm
安裝時報錯:
rpm -ivh powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm warning: powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID be1229cf: NOKEY error: Failed dependencies: libunwind is needed by powershell-6.0.0_alpha.9-1.x86_64 libicu is needed by powershell-6.0.0_alpha.9-1.x86_64
需要通過yum安裝兩個依賴包:
yum install -y libunwind libicu
安裝完成後,再次執行rpm安裝成功。
rpm -ivh powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm warning: powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID be1229cf: NOKEY Preparing... ################################# [100%] Updating / installing... 1:powershell-6.0.0_alpha.9-1 ################################# [100%]
成功後,可以執行powershell啟動powershell環境:
[root@hwslbvm02 ~]# powershell PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS /root> get-module ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...} Script 1.2 PSReadLine {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PSReadlineKeyHandler, Set-PSReadlineKey... PS /root> Get-PSRepository Name InstallationPolicy SourceLocation ---- ------------------ -------------- PSGallery Untrusted https://www.powershellgallery.com/api/v2/