How to Install PowerShell on Linux Distributions

PowerShell is a task automation and configuration management system developed by Microsoft. It’s includes a commandline shell and a framework for processing cmdlets. Inaddition, it's a very powerful object-oriented scripting language, with classes and methods, built on the .NET Framework.

It was originally a Windows-only component, which was later open-sourced and made cross-platform on 18 August 2016, making it available on Linux and Mac OS. In this article, I'll explain the installation of Powershell on all our latest popular Linux distributions.

Installing PowerShell on CentOS 7.4

Before installation, make sure to update all software requirements for compiling and installing the application. You can run "yum update" for the same. There are two methods for the installation, you can choose either of the two as your convenience.

1. Installation PowerShell via Direct RPM Download

After updating the system softwares, you can download the latest Powershell rpm for your OS distributions from the releases and install it by issuing the commands below:

#yum update.
#yum install -y wget
#wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.15/powershell-6.0.0_alpha.15-1.el7.centos.x86_64.rpm
# yum install -y powershell-6.0.0_alpha.15-1.el7.centos.x86_64.rpm

2. Installation using Microsoft Official Repo

Another method, is to enable Microsoft Official Repo corresponding to your OS distribution and install it from there. Please see the commands for registering the Microsoft Repo and installing from it below:

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

After installation, you can run the powershell, by just issuing this command "pwsh" in the prompt.

[[email protected] ~]# pwsh
PowerShell v6.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root> $PSVersionTable

Name Value
---- -----
PSVersion 6.0.0
PSEdition Core
GitCommitId v6.0.0
OS Linux 3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Jan 4 01:06:37 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS /root> cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

Uninstallation of PowerShell on CentOS 7.4

For removing this Powershell package from the server, you can execute "yum remove" command.

#yum remove powerhsell -y

Installing PowerShell on Ubuntu 17.10

As stated before, you need to update all software requirements for compiling and installing the application initially, Here also, we have two methods for the installations. There is no Powershell package releases available for this Ubuntu version 17.10 as of now. But the latest available repository for Ubunu 17.04 work here.

1. Installation via Direct Download of Package

You can download the Debain package to your Ubuntu server from the Powershell releases and install it using the commands below:

#apt-get update
#apt-get install wget
# wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0/powershell_6.0.0-1.ubuntu.17.04_amd64.deb
#dpkg -i powershell_6.0.0-1.ubuntu.17.04_amd64.deb
#apt-get install -f

2. Installation via Microsoft Official Repo

Powershell Core installation can be even done from the package repositories for easy installation. You just need to import the public repository keys and enable the Offical Ubuntu Microsoft Repository. Please follow these commands below:

#apt-get install curl
#curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
#curl https://packages.microsoft.com/config/ubuntu/17.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
#apt-get update
#apt-get install -y powershell
After installation, you can run the powershell, by just issuing this command "pwsh" in the prompt.

[email protected]:~# pwsh
PowerShell v6.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root> $PSVersionTable

Name Value
---- -----
PSVersion 6.0.0
PSEdition Core
GitCommitId v6.0.0
OS Linux 4.13.0-25-generic #29-Ubuntu SMP Mon Jan 8 21:14:41 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS /root> cat /etc/issue
Ubuntu 17.10 \n \l

Installing PowerShell on Debian 9.3

Before installation, make sure to update all software requirements for compiling and installing the application. Similar to the above cases, here also we have two installation methods.

1. Installation via Direct Download of Package

You can download the Debain package to your Debian 9 server from the Powershell releases and install it using the commands below:

#apt-get update
#apt-get install wget
#wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0/powershell_6.0.0-1.debian.9_amd64.deb
#dpkg -i powershell_6.0.0-1.debian.9_amd64.deb
#apt-get install -f

2. Installation via Microsoft Official Repo

Powershell installation can be even done from the package repositories for easy installation. Prior to the installation you need to enable some system components for the smooth functioning of the official repo. You can install those components by executing these commands below:

#apt-get update
#apt-get install curl gnupg apt-transport-https

Next you need to import the public repository keys and enable the Offical Debian Microsoft Repository. Please follow these commands below:

#curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
#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'
#apt-get update
#apt-get install -y powershell

After installation, you can start the powershell, by just issuing this command "pwsh" in the prompt.

[email protected]:~# pwsh
PowerShell v6.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root>
PS /root> $PSVersionTable

Name Value
---- -----
PSVersion 6.0.0
PSEdition Core
GitCommitId v6.0.0
OS Linux 4.9.0-5-amd64 #1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04)
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS /root> cat /etc/debian_version
9.3

Uninstallation of PowerShell on Ubuntu 17.10/Debian 9.3

For removing this Powershell package from your Ubuntu/Debian server, you can just execute "apt remove" command as below:

# apt remove powershell

Installing PowerShell on Fedora 27

Firstly, you can update all software requirements for installing this application. Similar to the above cases, there are two methods for the installation of Powershell in Fedora too.

1. Installation via Direct Download of Package

You can download the latest RHEL package to your Fedora server from the Powershell releases . Here I've downloaded the RPM package powershell-6.0.0-1.rhel.7.x86_64.rpm and installed it using the commands below:

#dnf update
#dnf install compat-openssl10
#dnf install wget
#wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0/powershell-6.0.0-1.rhel.7.x86_64.rpm
#dnf install powershell-6.0.0-1.rhel.7.x86_64.rpm

2. Installation via Microsoft Official Repo

Powershell installation can be done from the package repositories as well for easy installation.  You can import the public repository keys and enable the Offical Fedora Microsoft Repository for this. Please follow these commands below:

#dnf install curl
#rpm --import https://packages.microsoft.com/keys/microsoft.asc
#curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
#dnf update
#dnf install -y powershell

After installation, you can run the powershell, by just issuing this command "pwsh" in the prompt.

[[email protected] ~]# pwsh
PowerShell v6.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root> $PSVersionTable

Name Value
---- -----
PSVersion 6.0.0
PSEdition Core
GitCommitId v6.0.0
OS Linux 4.13.9-300.fc27.x86_64 #1 SMP Mon Oct 23 13:41:58 UTC 2017
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS /root> cat /etc/fedora-release
Fedora release 27 (Twenty Seven)

Uninstallation of PowerShell on Fedora 27

For removing this Powershell package from your Fedora server, you can  execute "dnf remove" command as below:

#dnf remove powershell -y

Wrapping up

Powershell offers complete access to WS-Management and CIM (Common Information Model) enabling administration of remote Linux systems plus network devices. In this tool, administrative tasks are basically carried out by particular .NET classes called cmdlets. Similar to shell scripts in Linux, users can build scripts or executables by storing groups of cmdlets in files by following certain rules. These scripts can be used as independent command-line utilities. Furthermore, it includes its own extensive, console-based help (similar to man pages in Linux commandline) accessible via the Get-Help cmdlet. You can type get-help in the Powershell console. In addition, local help contents can be retrieved from the Internet via Update-Help cmdlet in the console.

Saheetha Shameer 12:22 pm

About Saheetha Shameer

Self-motivated and dedicated Linux Administrator having 10 years of working experience on various web-hosting control panels and Unix distributions. I'm a quick learner and have a slight inclination towards following the current and emerging trends in the industry. I'm passionate about testing/reviewing new Linux applications and open source tools.

Author's All Posts
Like to become part of Linoxide Team and contribute tips? Contact us here.

Comments

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

All comments are subject to moderation.

1 Comment

  1. Great article. Have you considered following up with some Linux admin demos using PowerShell? Also maybe discussing what can not be done in Linux with PowerShell.