How to Install PowerShell on Ubuntu & Other Linux Distributions

Channel: Linux
Abstract: //packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo Then install PowerShell using the commandinstall PowerShel

Developed by Microsoft, PowerShell is a powerful tool that is used for automating tasks and simplifying configuration management. You can use it to automate virtually any tasks on a Windows environment including installing roles and features and making changes to the Active Directory on a Windows server system.

PowerShell is now officially supported on most Linux distributions. All the latest PowerShell Linux packages are available on GitHub.

In this guide, we explore ways that you can install PowerShell 7 on Ubuntu and other Linux distributions.

How to install terraform on ubuntu ...

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

How to install terraform on ubuntu 20.04

There are 2 main ways that you can install PowerShell.

  1. Using snap packages
  2. Using a package manager such as APT and YUM
Install PowerShell using Snap packages

Snap packages are prebuilt universal software applications that are distribution-agnostic and do not require dependencies during installation.

The simplest way to install PowerShell using snap is as follows :

$ sudo snap install powershell --classic

Then start PowerShell using the command:

$ pwsh

For a preview version, run the command:

$ sudo snap install powershell-preview  --classic

Perfect! Lets now see how you can install using package managers on various Linux flavors.

Install PowerShell on Ubuntu 18.04 and 20.04

The preferred method of installing PowerShell in Linux is from package repository.

To install PowerShell on Ubuntu 20.04 first update the package lists:

$ sudo apt update -y

Then install the prerequisite packages:

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

Next, use the wget command to download Microsoft's GPG keys

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

Then enable the GPG keys as follows:

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

Thereafter, update the system's package lists:

$ sudo apt-get update

The universe repository is also required to install all the required packages and dependencies. Therefore, install it as shown:

$ sudo add-apt-repository universe

Once the repository is added, once again, update the package lists to sync the repository.

$ sudo apt update

Finally, install Windows PowerShell as shown.

$ sudo apt install powershell -y

To check powershell version which is running, type:

pwsh --version

The following output shows the current version running is PowerShell 7.1.2:

PowerShell 7.1.2

To launch PowerShell, simply invoke:

$ pwsh
Launch PowerShell Install PowerShell on Debian 8/9/10

Let's now switch gears and focus on how to install PowerShell on Debian. The procedure is the same in Debian 8 and later versions with only a slight variation.

For Debian 10

For Debian Buster, begin by downloading the Microsoft GPG keys using the wget command as follows:

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

Next, enable the repository keys as shown:

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

Once that is done, be sure to update your package lists to sync with the new repository:

$ sudo apt-get update

Lastly, install PowerShell using the APT package manager as shown.

$ sudo apt install powershell -y

For Debian 8/9

Begin by update the package lists and install the requisite packages.

$ sudo apt-get update
$ sudo apt-get install -y curl gnupg apt-transport-https

Next, import the public Microsoft GPG keys.

$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

Next, enable the Microsoft repository.

For Debian 9 Stretch:

$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'

For Debian 8 Jessie:

$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/microsoft.list'

Next, update the package lists

$ sudo apt-get update

And finally install PowerShell

$ sudo apt install powershell -y
Install PowerShell on Kali

On Kali, the process is quite straight-forward. Simply update the package lists and run the commands:

$ sudo apt update
$ sudo apt install powershell -y
Install PowerShell on Fedora 28/29/30

For Fedora 28 and later, follow the commands below

Start off by registering Microsoft signature key.

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

Later, register the Microsoft RedHat repository.

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

Next, install the OpenSSL package shown:

$ sudo dnf install compat-openssl10

Finally install PowerShell as shown

$ sudo dnf install  powershell -y
Install PowerShell on CentOS/RHEL 7 & 8

On CentOS/RHEL 7 & 8 invoke the following commands.

First, begin with registering the Microsoft Red Hat repository by creating a new repository file.

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

Then install PowerShell using the command:

$ sudo yum install powershell -y
Install PowerShell on OpenSUSE Leap 15 & OpenSUSE 42.3

In openSUSE, we are going to install PowerShell from a compressed file - tarball file.

Begin by updating the system and installing dependencies:

$ sudo zypper update
$ sudo zypper --non-interactive install curl tar libicu52_1

Next, download the PowerShell '.tar.gz' archive from GitHub.

$ curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.1.0/powershell-7.1.0-linux-x64.tar.gz -o /tmp/powershell.tar.gz

Thereafter, proceed and make a target directory where PowerShell will be placed:

$ sudo mkdir -p /opt/microsoft/powershell/7

Next, extract the tarball file to the newly created folder.

$ sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7

You will notice a PowerShell folder called pwsh. You need to give this folder execute permissions. So proceed and use the chmod command as shown.

$ sudo chmod +x /opt/microsoft/powershell/7/pwsh

Finally, create a symbolic link as shown below.

$ sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
Conclusion

PowerShell installation .deb and .rpm files are available on GitHub if you wish to install directly.

In this guide, we learned how to install PowerShell on Ubuntu and other Linux distributions. Thank you for reading and let us know if you encounter any issues installing PowerShell.

Ref From: linoxide
Channels:

Related articles