How to Install PowerShell on Ubuntu 22.04 / Ubuntu 20.04
PowerShell is a task automation and configuration program consisting of a command-line shell and scripting language. It was initially developed as a Windows component known as Windows PowerShell. Then, later, in 2016, with the introduction of PowerShell Core, it was made open-source and cross-platform.
PowerShell is available for Windows, Linux, and macOS.
Install PowerShell on Ubuntu 22.04 / 20.04
1. Install PowerShell Using Snap
Installing PowerShell using snap
sudo apt install -y snap is the quickest way to install it on Ubuntu.
snap command to install PowerShell.
sudo snap install powershell --classic
snap install powershell-preview --classiccommand.
After the installation is complete, validate the PowerShell installation using the below command.
sudo snap list powershell
Name Version Rev Tracking Publisher Notes powershell 7.2.2 202 latest/stable microsoft-powershell✓ classic
2. Install PowerShell Using Official Repository
Microsoft offers a dedicated repository for the PowerShell package for Linux operating systems. We will now set up the Microsoft repository and install PowerShell.
When writing this post, the Microsoft PowerShell repository doesn’t have the PowerShell package for Ubuntu 22.04. So, I recommend installing PowerShell from the Snap store on Ubuntu 22.04.
The below steps may work in the coming days.
First, download the Microsoft repository configuration package.
# Ubuntu 22.04 wget -q https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb # Ubuntu 20.04 wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
Then, install the Microsoft repository configuration package.
sudo dpkg -i packages-microsoft-prod.deb
After adding the Microsoft repository for PowerShell, update the repository index with the below command.
sudo apt update
Finally, install the PowerShell package using the
sudo apt install -y powershell
sudo apt install -y powershell-previewcommand.
You can start the PowerShell on Ubuntu by going to Activities >> search for PowerShell or with the
pwsh command. PowerShell preview with