×


Install Microsoft PowerShell in Ubuntu 20.04 - How to perform this task ?

Basically, 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.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform PowerShell related queries.

In this context, we shall look into different ways to install Microsoft PowerShell on Ubuntu.


How to install Microsoft PowerShell on Ubuntu 20.04 LTS ?

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

a. Installation via Package Repository

b. Installation via .deb package

c. Installation via snap


a. How to Install Microsoft PowerShell via Package Repository ?

To begin with the installation process, ensure that you log into the server with a user with sudo privileges.

Then, follow the steps below to install PowerShell on your Ubuntu system.


1. Install prerequisites

Start by installing some prerequisites on your system. Execute 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.


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. Run the below command in Terminal to install the package:

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


3. Update repository index

Now update the repository index using the following command:

$ sudo apt update


4. Enable universe repository

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

$ sudo add-apt-repository universe


5. Install Microsoft PowerShell

Now we are ready to install Microsoft PowerShell on our system. Run 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.


b. How to install Microsoft PowerShell via .deb package ?

Microsoft PowerShell can also be installed through the .deb package. 

i. You will first have to download the .deb package of Microsoft PowerShell through the following link.

https://github.com/PowerShell/PowerShell/releases/download/v7.1.1/powershell_7.1.1-1.ubuntu.20.04_amd64.deb

ii. After clicking the above link, a window will appear asking you to either open or save the file. 

iii. Select the Save File option and after that click OK. Now the file will be downloaded and saved to the Downloads directory.

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

$ cd Downloads

v. Then install Microsoft PowerShell using the following command in Terminal:

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


c. How to Install 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.


How to Launch PowerShell on Ubuntu ?

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.


How to Uninstall PowerShell from Ubuntu System ?

In case you no longer need PowerShell, you can easily remove it from your system. Run 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, run the following command in Terminal:

$ sudo apt autoremove

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

$ sudo snap remove powershell


[Need urgent assistance in fixing Powershell related errors on Ubuntu? We are available to help you. ]


Conclusion

This article covers the different methods for installing Microsoft PowerShell on Ubuntu which includes installation via package repository, via .deb package, and via snap. 

PowerShell for Linux is published to package repositories for easy installation and updates. 

As superuser, register the Microsoft repository once. 

After registration, you can update PowerShell with sudo apt-get install powershell.


To install PowerShell on Ubuntu 20.04:

PowerShell for Linux is published to package repositories for easy installation and updates.

So do the following;

1. # Update the list of packages.

$ sudo apt-get update

2. # Install pre-requisite packages.

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

3. # Download the Microsoft repository GPG keys.

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

4. # Register the Microsoft repository GPG keys.

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

5. # Update the list of products.

$ sudo apt-get update

6. # Enable the "universe" repositories.

$ sudo add-apt-repository universe

7. # Install PowerShell.

$ sudo apt-get install -y powershell

8. # Start PowerShell.

$ pwsh

As superuser, register the Microsoft repository once.

After registration, you can update PowerShell with sudo apt-get install powershell.


To remove PowerShell from Ubuntu:

Run the command,

$ sudo apt-get remove powershell


How to Launch PowerShell on Linux or Mac?

1. Open a terminal and run the "powershell" command to access a PowerShell shell environment. 

2. This works on both Linux and Mac–whichever you're using. 

3. You'll see a PowerShell prompt beginning with "PS", and you can run PowerShell cmdlets just as you would on Windows.