How to install Microsoft PowerShell on Linux

Powershell on Linux
Powershell on Linux (Image credit: Windows Central)

PowerShell has been a staple of Windows for many years but in recent times Microsoft has made a pretty substantial change to it. It's now both open source and cross-platform, available not only on Windows but also on macOS and Linux.

This new version is the future of PowerShell and whether you want to use it on Linux professionally, to learn, or just to poke around with, it's not too difficult to get installed.

Here's what you need to know.

Downloading and installing PowerShell on Linux

Powershell

Source: Windows Central (Image credit: Source: Windows Central)

While PowerShell on Linux isn't exactly the same as on Windows — modules and commands specific to Windows aren't usable — it's available for folks who need it. Microsoft is moving away from Windows PowerShell and into this cross-platform affair.

We'll be installing PowerShell 7, and the process is really straightforward.

  1. Go to the PowerShell release page.
  2. Download the installer that matches your Linux distro.
  3. Locate the downloaded file on your machine.
  4. Double click to install.

A fairly short installation process will now occur, using a software installer that may vary depending on which distro you're using.

Powershell being a command-line tool on Linux and not a traditional application means you won't be able to launch it directly from your desktop GUI. Instead, you'll launch it from the terminal.

If you're on Arch Linux you can install PowerShell from the AUR by grabbing the latest release binary.

You could also use the Snap Store to install PowerShell if that's a way you like to get your packages.

snap install powershell --classic

One final word is that the official Microsoft documentation says that PowerShell 7 isn't supported on Ubuntu 20.04 LTS, but that's not really the case. Whether it's a missing update to the text or it just works anyway, PowerShell in this guide was installed on Ubuntu 20.04. Admittedly there were some issues using the direct download but the Snap install works just fine.

How to launch PowerShell inside the terminal

You may see PowerShell in your app drawer but to use it, open up a new terminal window and enter this simple command.

pwsh

You'll now see a short bit of blurb beginning with the PowerShell version, and your command line will change from yourusername@yourlinuxmachine to PS /home/yourusername.

You're now all set to use PowerShell on your Linux machine. Any time you want to use it, simply enter the command to launch it and exit out when you're done by typing exit.

But if you're going to use it a lot, you might want to set it as the default shell for your Linux terminal.

Setting PowerShell as the default terminal shell

Powershell on Linux

Source: Windows Central (Image credit: Source: Windows Central)

PowerShell's bonus is that it doesn't totally replace and overwrite your existing shell; any Linux commands you could normally enter can also be entered in PowerShell. As such, if you're going to use PowerShell a lot, you can set it as your default shell and not worry about losing any functionality.

There are a few different ways you can achieve this, but one of the easiest is by changing the default in

/etc/passwd

and if you installed it as a Snap then there's a slight difference to the steps.

First up, it's a good idea to make sure PowerShell is added as a valid login shell in

/etc/shells

.

Source: Windows Central (Image credit: Source: Windows Central)
  1. In the terminal enter sudo nano /etc/shells (substituting nano for your preferred text editor as required).
  2. If you see an entry for pwsh then you're good and can close the file.
  3. If you need to add PowerShell, type /usr/bin/pwsh to the end of the text file.
  4. If you installed via Snap, add /snap/bin/pwsh instead.
  5. Close out of nano by pressing ctrl + X and selecting yes to save.

Next, in the terminal, follow these steps.

  1. Enter sudo nano /etc/passwd (again, substitute nano for your preferred text editor as required).

Source: Windows Central (Image credit: Source: Windows Central)
  1. Scroll towards the bottom until you see an entry that ends in /bin/bash.
  2. Change this to either /bin/pwsh or if you installed from Snap /snap/bin/pwsh.

Powershell on Linux

Source: Windows Central (Image credit: Source: Windows Central)
  1. Exit and save the file.
  2. Log out of your PC and log back in.

Once logged back in opening a new terminal window should now immediately present you with PowerShell in place of the standard bash shell.

Richard Devine
Managing Editor - Tech, Reviews

Richard Devine is a Managing Editor at Windows Central with over a decade of experience. A former Project Manager and long-term tech addict, he joined Mobile Nations in 2011 and has been found on Android Central and iMore as well as Windows Central. Currently, you'll find him steering the site's coverage of all manner of PC hardware and reviews. Find him on Mastodon at mstdn.social/@richdevine