Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / PowerShell / Installing PowerShell Core on Linux Distros

May 10, 2023 CentOSLinuxPowerShellRHELUbuntu

Installing PowerShell Core on Linux Distros

Today, PowerShell is an open cross-platform shell and scripting language that can be installed and used on Windows, Linux, macOS, and other platforms. In this article, we’ll show how to install PowerShell Core on popular Linux distros (CentOS, RHEL, Debian, Kali, Mint, Ubuntu). The article is likely to be helpful for Windows administrators familiar with PowerShell to bring their experience in Linux.

Contents:
  • How to Install PowerShell Core in Ubuntu 20.04 & Linux Mint 20?
  • Installing PowerShell Core on Debian 11
  • Hot to Install PowerShell on Red Hat Enterprise Linux (RHEL) and CentOS?
  • PowerShell Core 7.x Installation in Kali Linux
  • Installing PowerShell on Linux with Snap
  • How to Remove PowerShell in Linux?
  • How to Run and Use PowerShell Core on Linux?

  • A complete list of compiled PowerShell packages for different platforms is available in the official Microsoft repository: https://github.com/PowerShell/PowerShell/releases
  • You can find more information about PowerShell support in different Linux distros and versions here: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.2

Currently, the PowerShell package is missing from almost all default Linux repositories. So, to install PowerShell in Linux, you have to download the Microsoft repository package first, import the keys, and use the Linux package manager to install PowerShell.

Note that only PowerShell Core (based on .NET Core) may be installed on Linux. You cannot install classic Windows PowerShell 5.1 in Linux. The latest PowerShell Core version available at the time of this writing is PowerShell Core 7.2 LTS.

How to Install PowerShell Core in Ubuntu 20.04 & Linux Mint 20?

Before installing PowerShell in Ubuntu or Linux Mint, you need to update the list of packages:

sudo apt-get update -y

Download GPG keys of Microsoft repository:

wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

Install Microsoft GPG keys:

sudo dpkg -i packages-microsoft-prod.deb

Update the package list with packages from packages.microsoft.com:

sudo apt-get update

Install PowerShell:

sudo apt-get install powershell -y

apt-get install powershell ubuntu

The PowerShell package will be automatically updated by the apt package manager:

sudo apt update

If a previous PowerShell Core version was installed on your computer, it will be removed.

You can also download and install the PowerShell DEB package manually:

wget -q https://github.com/PowerShell/PowerShell/releases/download/v7.2.0/powershell-lts_7.2.0-1.deb_amd64.deb
sudo dpkg -i powershell_7.2.0-1.deb_amd64.deb

Resolve dependencies and finish the installation:

sudo apt-get install -f

Installing PowerShell Core on Debian 11

To install PowerShell Core 7.0+ in Debian 11 Bullseye, download the GPG keys for the Microsoft repository first:

wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb

Then add the GPG key you have downloaded:

sudo dpkg -i packages-microsoft-prod.deb

Update the app list in the package manager:

sudo apt update

Install PowerShell:

sudo apt install -y powershell

installing powershell core on debian linux

PowerShell will be updated automatically when you run package update using the command below:

sudo apt update

If you want to update the PowerShell package only:

sudo apt install powershell

Hot to Install PowerShell on Red Hat Enterprise Linux (RHEL) and CentOS?

PowerShell in Linux CentOS and Red Hat Enterprise Linux (RHEL), Oracle Linux is installed in the same way:

Add the Microsoft RedHat repository to YUM:

curl https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

Install the latest available PowerShell Core version using yum (or dnf) package manager:

sudo yum install -y powershell

how to install powersehll on Red Hat (RHEL) Linux

You can update the PoSh package with the command:

sudo yum update powershell

Also, you can also install PowerShell from an RPM file:

sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v7.2.0/powershell-lts-7.2.0-1.rh.x86_64.rpm

PowerShell Core 7.x Installation in Kali Linux

To install PowerShell in Kali, it is enough to run the command below:

apt update && apt -y install powershell

Installing PowerShell on Linux with Snap

You can use snap to install PowerShell in different Linux distros. This installation method is recommended for Linux distributions without official PoSh support.

The command to install PowerShell using snap is:

sudo snap install powershell --classic

In snap, PowerShell is updated automatically, but you can also do it manually:

sudo snap refresh powershell

How to Remove PowerShell in Linux?

Let’s learn the commands to remove PowerShell in different Linux distributions:

  • To remove PowerShell Core in Ubuntu/Linux Mint: sudo apt remove powershell
  • To remove PowerShell in Debian: sudo apt remove powershell
  • To remove PowerShell in Kali Linux: sudo apt -y remove powershell
  • To remove PowerShell in CentOS or RHEL: sudo yum remove powershell
  • To remove PowerShell using Snap: sudo snap remove powershell

How to Run and Use PowerShell Core on Linux?

To run PowerShell command shell on Linux, run the command below:

pwsh

You can check the version of PowerShell installed on the Ubuntu host with the command:

$PSVersionTable

When typing PowerShell commands, you can use the code auto-completion feature with the TAB key.

In our example, PowerShell Core 7.2.0 is installed:

PSVersion 7.2.0
PSEdition Core
OS Linux 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021
Platform Unix

running powershell (pwsh) on Linux

You can see that commands that the commands in the PowerShell shell take several times longer to complete than in the bash. You can compare the command execution time:

time pwsh -Command Get-History
time bash -c history

linux get command execution time

By default, some built-in PowerShell modules are available on Linux:

Get-Module –ListAvailable

  • Microsoft.PowerShell.Archive
  • Microsoft.PowerShell.Host
  • Microsoft.PowerShell.Management
  • Microsoft.PowerShell.Security
  • Microsoft.PowerShell.Utility
  • PackageManagement
  • PowerShellGet
  • PSReadLine
  • ThreadJob

built-in powershell modules on linux

You can install other modules, including VMWare PowerCLI.

To get the current date:

Get-date

Check host uptime:

get-Uptime

To list the contents of the current directory:

Dir

Or:

Get-ChildItem

getting started with PowerShell on Linux

Note that PowerShell commands on Linux are not case-insensitive.

To display the PowerShell command history:

History

To get help on the command:

Get-help Get-History

To run a PowerShell script from bash:

pwsh /home/sysops/CheckSpace.ps1

We will tell more about features and scenarios of using PowerShell for Linux administration and automation in the next article.

1 comment
4
Facebook Twitter Google + Pinterest
previous post
Outlook: The Name Cannot Be Matched to a Name in the Address List
next post
VMware PowerCLI: How to Install and Manage vSphere and ESXi

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

1 comment

chuanjiao10 February 28, 2022 - 3:49 pm

[kasini3000_agent_linux](_https://gitee.com/chuanjiao10/kasini3000_agent_linux) Shell script,one click install powershell on linux,modify sshd_config for PsRemote.

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Install and Configure SNMP on RHEL/CentOS/Fedor
  • How to Install and Use ClamAV Antivirus on CentOS/RHEL?
  • Configuring Network Settings on RHEL/CentOS
  • How to Install and Configure Squid Proxy Server on Linux
  • Adding Trusted Root Certificates on Linux
  • Configuring Routing on Linux (RHEL/CentOS)
  • Zabbix – Simple ICMP Ping Checks
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top