How to Install PowerShell on Ubuntu

🐧Part of the WSL Complete Guide, every Windows Subsystem for Linux post on this site, organised by task.

To install PowerShell on Ubuntu, add Microsoft’s package repository and install the powershell package with apt, then start it with pwsh. The same steps work on Ubuntu 22.04, 24.04 and 26.04, on a server or in WSL.

I first wrote this for Ubuntu 20.04 in WSL, which has since reached the end of its support. The commands below look up your Ubuntu version for you, so they work unchanged on whichever release you are on.

Install PowerShell

Shell
# Prerequisites
sudo apt-get update
sudo apt-get install -y wget apt-transport-https software-properties-common

# Download and register Microsoft's repository for your Ubuntu version
source /etc/os-release
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

# Install PowerShell
sudo apt-get update
sudo apt-get install -y powershell

source /etc/os-release sets $VERSION_ID to your release (for example 24.04), so the download matches your system. The older version of this post skipped the download line, so the dpkg step failed with “cannot access archive”. Microsoft’s Install PowerShell on Ubuntu page lists which releases are supported.

apt installing the powershell package on Ubuntu in WSL in 2022

Start PowerShell and Check the Version

Shell
pwsh
Starting PowerShell on Ubuntu with the pwsh command

Inside PowerShell, check which version you have:

PowerShell
$PSVersionTable.PSVersion
$PSVersionTable showing the PowerShell version on Ubuntu

Type exit to go back to bash. To update PowerShell later, it updates with everything else: sudo apt-get update && sudo apt-get upgrade.

The screenshots are from my 2022 install. More on checking versions, including on Windows, is in How to Check Your PowerShell Version, and the Windows install is in Install PowerShell 7 on Windows. Other installs on the same Ubuntu: Ubuntu on WSL itself, the AWS CLI and PostgreSQL. Every other WSL post is in the WSL Complete Guide.

If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.