Over the years, Microsoft has grown to appreciate Opensource with Linux as its key focus, now, and you can easily install PowerShell on Linux without any license. At first, as it is with most Microsoft products, PowerShell was closed source, but later made opensource making available on Linux and macOS operating systems.
The major difference you experience when you install PowerShell on Linux is the ability to run Windows-cmd-like commands on your system. This is due to the fact that Linux runs Bash as its default shell, when you install PowerShell, you can make it the default, or simply use it to run your commands as you would on Windows.
The shell offers full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI) which makes it easy to carry out administrative tasks on Windows system in the same LAN environment. Likewise, the Common Information Model (CIM) enables remote management of the Linux systems where you have PowerShell installed.
To install PowerShell on Linux and use the .NET framework as your scripting language, you need to add the official Microsoft repositories to your system and install PowerShell as described below.
Install PowerShell on Ubuntu
In a new terminal session, run the following commands:
Update your system.
$ sudo apt update
Install dependencies.
$ sudo install wget apt-transport-https software-properties-common -y
Download the Microsoft production package for Ubuntu.
$ wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"
> The above command will use your current distribution listed by the command lsb_release -rs
to get the appropriate package.
Install the downloaded package.
$ sudo apt install ./packages-microsoft-prod.deb
Update the system.
$ sudo apt update
Install PowerShell.
$ sudo apt install powershell -y
Verify that PowerShell is installed by checking the version.
$ pwsh --version
Install PowerShell on Debian
Update the system
$ sudo apt update
Install dependencies.
$ sudo apt install -y wget apt-transport-https -y
Download the Microsoft package for your Debian system.
$ wget https://packages.microsoft.com/config/debian/$(lsb_release -rs)/packages-microsoft-prod.deb
Update the system.
$ sudo apt update
Install PowerShell.
$ sudo apt install powershell -y
Verify that PowerShell is installed on your Debian system.
$ pwsh --version
Install PowerShell on Linux Mint
Linux Mint is based on the Debian distribution just like Ubuntu, to install PowerShell on Linux Mint, download and install the latest package for Debian systems as below.
Update Linux Mint.
$ sudo apt update
Download the latest Debian package.
$ wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb
> The above package downloads a Debian 11 package, if your Linux Mint system is up to date, consider using the latest Debian distribution package by replacing the distro number.
Install PowerShell on Linux Mint.
$ sudo apt install powershell
Verify the install PowerShell version.
$ pwsh --version
Install PowerShell on CentOS, AlmaLinux, RockyLinux, and RHEL distributions
Depending on your CentOS, AlmaLinux, RockyLinux or Redhat Enterprise Linux (RHEL) version, follow the steps below to install PowerShell.
CentOS stream 9, Rocky Linux 9, Alma Linux 9, RHEL 8
Install Curl.
$ sudo dnf install curl -y
Import the Microsoft Repository.
$ $ curl https://packages.microsoft.com/config/rhel/9.0/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
Update the system.
$ sudo dnf update
Install PowerShell.
$ sudo dnf instal powershell -y
CentOS 8, RHEL 8, Rocky Linux 8, Alma Linux 8
Import the Microsoft Repository.
$ curl https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
Update the system.
$ sudo yum update
Install PowerShell.
$ sudo yum install powershell
Verify that PowerShell is installed by checking the version.
$ pwsh --version
Install PowerShell on Fedora Linux
Update the system.
$ sudo dnf update
Download the latest `rpm` package for your Fedora system.
$ wget https://packages.microsoft.com/config/fedora/$(lsb_release -rs)/packages-microsoft-prod.rpm
Install the package.
$ sudo dnf install powershell
Verify that PowerShell is installed.
$ pwsh --version
Install PowerShell on OpenSuse
Download the latest `rpm` packager for OpenSuse.
$ wget https://packages.microsoft.com/config/opensuse/$(lsb_release -rs)/packages-microsoft-prod.rpm
Install the Package.
$ sudo zypper install packages-microsoft-prod.rpm
Verify that PowerShell is installed.
$ pwsh --version
Conclusion
In this article, you have managed to install PowerShell on Linux. If you’re a Windows administrator, PowerShell makes it easy to run commands and automate your tasks as you would on a Windows server. However, the bash shell will remain as the default Shell unless you change it when adding new users.