Menu & Search

How to Install PowerShell on Ubuntu 20.04

How to Install PowerShell on Ubuntu 20.04

This post is a guide on installing PowerShell on Ubuntu 20.04.

The Ubuntu Linux distribution being used in this demo is running as a Windows Subsystem for Linux (WSL) instance. I have not yet encountered issues with the PowerShell, Ubuntu and WSL cocktail.

Be sure to check out Microsoft Documentation, Installing PowerShell on Linux (Ubuntu) for up-to-date information, particularly for PS Linux version compatibility and end-of-support dates.

The following is covered in this demo:
# Install PowerShell on Ubuntu
# Open PowerShell on Ubuntu

Install PowerShell on Ubuntu

As mentioned above, I’m installing PowerShell on Ubuntu WSL for this demo. Why would you want to emulate Linux on Windows to then install PowerShell? Because it’s a great cross-platform programming language? The reason I’m performing this on WSL is that the Windows Subsystem is great for spinning up a test Ubuntu instance.

To install PowerShell on Ubuntu 20.04, run through the Linux commands below. This is as described in the Install via Package Repository Microsoft documentation page, be sure to check that out for any updated information.

# Update the list of packages
sudo apt-get update

# Install pre-requisite packages.
sudo apt-get install -y wget apt-transport-https software-properties-common

# Download the Microsoft repository GPG keys
wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"

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

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

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

The above PowerShell installation should only take a minute or so to complete, including the Advanced Package Tool (apt) updates.

Open PowerShell on Ubuntu

Now that we have PowerShell installed on this Ubuntu WSL instance, we can check the running PowerShell version and open PowerShell in Ubuntu.

The default Alias for PowerShell is pwsh. You can find information about pwsh and pwsh parameters within the MS Docs as linked.

# Check PowerShell Version on Ubuntu
pwsh -v

# Start PowerShell on Ubuntu
pwsh
Run PowerShell Ubuntu

The above shows the running PowerShell version of 7.2.7, and we are entering PowerShell using the pwsh command.

We can also run $PSVersionTable while in pwsh to check the PowerShell version in Ubuntu, which will show more OS and system information.

Get PowerShell Version Ubuntu

I hope this has been a helpful informational guide on installing PowerShell on Ubuntu. If you are interested in running Ubuntu on Windows, check out my other post – How To Install Windows Subsystem for Linux (WSL).