How to Install PowerShell in Linux/Ubuntu

Install Powershell in Linux

This easy-to-follow tutorial shows you how to install PowerShell on a variety of Linux systems.

What is PowerShell?

Like Linux has Bash, Zsh, and other interactive shells for issuing commands to the system via the terminal, Windows has PowerShell. It’s the successor to the Windows Command Prompt. It allows the user to type commands for execution and provides features for automation and scripting.

And now, it runs on Linux.

This is useful if you administer Windows servers remotely or interact with Microsoft’s Azure Cloud services. Certain tasks in Office 365 are also only achievable from the command line, so connecting to them via PowerShell on Linux is quite useful for system administrators.

Installing PowerShell in Ubuntu (> 18.04)

The following commands will install PowerShell on Ubuntu versions newer than 18.04.

While it’s possible to download a package installer, when possible, it’s preferred to install from a repository so that PowerShell is automatically kept up to date by the package manager.

First, update the list of packages available on the system:

sudo apt-get update

Adding a repository has some prerequisites, so install those next:

sudo apt-get install -y wget apt-transport-https software-properties-common

Download the Microsoft repository GPG keys – these keys ensure that the server providing the packages cannot be impersonated:

wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb

Register the keys downloaded in the last step:

sudo dpkg -i packages-microsoft-prod.deb

Update the package lists again:

sudo apt-get update

Enable the “universe” repositories to make the PowerShell package available for installation:

sudo add-apt-repository universe

PowerShell can now be installed:

sudo apt-get install -y powershell

Once installed, PowerShell can be started by executing:

pwsh

Once you’re up and running, you can remove the downloaded packages file:

rm packages-microsoft-prod.deb

Installing PowerShell in Debian (> 10)

The process for installing PowerShell in Debian versions 10 and greater is similar to that of Ubuntu.

Download the Microsoft repository GPG keys – these keys ensure that the server providing the packages cannot be impersonated:

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

Register the keys downloaded in the last step:

sudo dpkg -i packages-microsoft-prod.deb

Update the package lists:

sudo apt-get update

PowerShell can now be installed:

sudo apt-get install -y powershell

Once installed, PowerShell can be started by executing:

pwsh

Once you’re up and running, you can remove the downloaded packages file:

rm packages-microsoft-prod.deb

Installing PowerShell in Fedora Linux

Installing PowerShell on Fedora Linux is just as easy as it is on Ubuntu/Debian.

Download the Microsoft repository GPG keys – these keys ensure that the server providing the packages cannot be impersonated:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

Register the Microsoft RedHat repository, which includes the PowerShell package:

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

Update the list of available packages:

sudo dnf check-update

Install the required dependencies:

sudo dnf install compat-openssl10

PowerShell can now be installed:

sudo dnf install -y powershell

Once installed, PowerShell can be started by executing:

pwsh

Using PowerShell

Linux Powershell

Blasphemy! PowerShell is now up and running on your Linux system.

However, using it is outside the scope of this article – it’s a big subject, and it’s definitely more Windows-y than Linux-y.

Microsoft has been really good with their documentation lately, so the best place to get started is with their own ‘Getting Started’ tutorial.

More documentation for installing PowerShell on Linux is also available in the official Microsoft documentation.

SHARE:
nv-author-image

Brad Morton

I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Reply

Your email address will not be published. Required fields are marked *