Ubuntu

How to Install Microsoft PowerShell in Ubuntu 20.04

Install Microsoft PowerShell on Ubuntu 20.04

Almost all Windows system administrators are well familiar with PowerShell utility. PowerShell developed by Microsoft is powerful work automation and configuration management utility. It was previously developed only for the Windows platform. However, it can now be easily installed in a Linux OS. In this post, we will be sharing with you different ways to install Microsoft PowerShell on Ubuntu.

Microsoft PowerShell can be installed in Ubuntu via following three different ways:

  • Installation via Package Repository
  • Installation via .deb package
  • Installation via snap

Note: The procedures and the commands shared here have been performed on Ubuntu 20.04 LTS (Focal Fossa). For installing any application on the Ubuntu system, you must have sudo privileges.

Installing Microsoft PowerShell via Package Repository

You should follow the steps below in order to install PowerShell on your Ubuntu system:

Step 1: Install prerequisites

First, you will need to install some prerequisites on your system. Issue the following command in Terminal to install the prerequisites:

$ sudo apt install apt-transport-https software-properties-common

Enter the password for sudo, after which the installation of prerequisites will be started. Once the prerequisites are installed, move on to the next step.

Step 2: Download and install Microsoft Repository GPG Keys

Download the Microsoft Repository GPG Keys using the following command in Terminal:

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

Once downloaded, you will need to install this package. Issue the below command in Terminal to install the package:

$ sudo dpkg -i packages-microsoft-prod.deb

Step 3: Update repository index

Now update the repository index using the following command:

$ sudo apt update

Step 4: Enable universe repository

Now you will need to enable the universe repository using the following command in Terminal:

$ sudo add-apt-repository universe

Step 5: Install Microsoft PowerShell

Now we are ready to install Microsoft PowerShell on our system. Issue the following command to do so:

$ sudo apt install powershell

Now you might be provided with the y/n choice to continue or terminate the installation procedure respectively. Hit y to continue the installation.

Installing Microsoft PowerShell via .deb package

Microsoft PowerShell can also be installed through the .deb package. You will first have to download the .deb package of Microsoft PowerShell through the following link.

powershell_7.1.1-1.ubuntu.20.04_amd64.deb

After clicking the above link, a window will appear asking you to either open or save the file. Select the Save File option and after that click OK. Now the file will be downloaded and saved to the Downloads directory.

Now in order to install Microsoft PowerShell, first move to the Downloads directory that contains the .deb package for the Microsoft PowerShell.

$ cd Downloads

Then install Microsoft PowerShell using the following command in Terminal:

$ sudo dpkg -i powershell_7.1.1-1.ubuntu.20.04_amd64.deb

Installing Microsoft PowerShell via Snap

Microsoft PowerShell is also available as a snap package that is bundled with all the dependencies required for the installation of PowerShell.

To install any snap package on Ubuntu, you must have snapd available on your system. You can install snapd by running this command in Terminal:

$ sudo apt install snapd

Then in order to install PowerShell in your system, execute the below command in Terminal:

$ sudo snap install powershell --classic

Once installed, you will see the installation completed message as shown in the following screenshot:

Launch PowerShell

Once the Microsoft PowerShell is installed, you can launch it right from the Terminal using the following command:

$ pwsh

After running the above command, PowerShell will be launched and you will see the prompt has changed to PS.

Uninstall PowerShell

In case you no longer need PowerShell, you can easily remove it from your system. Issue the following command in Terminal to uninstall PowerShell:

$ sudo apt remove powershell

During the installation of PowerShell, some packages are automatically installed as dependencies. In order to remove those packages too, issue the following command in Terminal:

$ sudo apt autoremove

To uninstall PowerShell that was installed via snap, issue the following command in Terminal:

$ sudo snap remove powershell

That is all there is to it! In this post, we have discussed three different methods for installing Microsoft PowerShell on Ubuntu which includes installation via package repository, via .deb package, and via snap. Using either of the above-described methods, you can simply install and use PowerShell on your system.

Similar Posts