Install PowerShell Core on Ubuntu / CentOS using package management

Microsoft has release latest bits of PowerShell core and published PowerShell Core 6.0 alpha.15 to https://packages.microsoft.com. So we can use package management tools like yum or apt-get to install the latest PowerShell version on Linux distributions. It’s as simple as registering the Microsoft repository once as superuser and then just need to use either sudo apt-get install powershell or sudo yum update powershell (depending on which distribution you are using) to update it

Install PowerShell Core on Ubuntu 16.04

Install PowerShell Core on CentOS

Here’s a sample output from CentOS 7 machine:

[root@localhost userContent]# yum install -y powershell
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
jenkins | 2.9 kB 00:00
packages-microsoft-com-prod | 2.9 kB 00:00
updates | 3.4 kB 00:00
(1/3): packages-microsoft-com-prod/primary_db | 9.6 kB 00:00
(2/3): updates/7/x86_64/primary_db | 2.2 MB 00:01
(3/3): jenkins/primary_db | 19 kB 00:06
Loading mirror speeds from cached hostfile
* base: mirror.fibergrid.in
* extras: mirror.fibergrid.in
* updates: mirror.fibergrid.in
Resolving Dependencies
–> Running transaction check
—> Package powershell.x86_64 0:6.0.0_alpha.15-1.el7.centos will be installed
–> Processing Dependency: uuid for package: powershell-6.0.0_alpha.15-1.el7.cen tos.x86_64
–> Running transaction check
—> Package uuid.x86_64 0:1.6.2-26.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================

Package Arch Version Repository Size

Installing:
powershell
x86_64 6.0.0_alpha.15-1.el7.centos packages-microsoft-com-prod 39 M
Installing for dependencies:
uuid x86_64 1.6.2-26.el7 base 55 k

Transaction Summary

Install 1 Package (+1 Dependent package)

Total download size: 39 M
Installed size: 39 M
Downloading packages:
(1/2): uuid-1.6.2-26.el7.x86_64.rpm | 55 kB 00:00
warning: /var/cache/yum/x86_64/7/packages-microsoft-com-prod/packages/powershell -6.0.0_alpha.15-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY
Public key for powershell-6.0.0_alpha.15-1.el7.centos.x86_64.rpm is not installe d

(2/2): powershell-6.0.0_alpha.15-1.el7.centos.x86_64.rpm | 39 MB 00:05

Total 6.9 MB/s | 39 MB 00:05
Retrieving key from https://packages.microsoft.com/keys/microsoft.asc
Importing GPG key 0xBE1229CF:
Userid : “Microsoft (Release signing) ”
Fingerprint: bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf
From : https://packages.microsoft.com/keys/microsoft.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : uuid-1.6.2-26.el7.x86_64 1/2
Installing : powershell-6.0.0_alpha.15-1.el7.centos.x86_64 2/2
Verifying : powershell-6.0.0_alpha.15-1.el7.centos.x86_64 1/2
Verifying : uuid-1.6.2-26.el7.x86_64 2/2

Installed:
powershell.x86_64 0:6.0.0_alpha.15-1.el7.centos

Dependency Installed:
uuid.x86_64 0:1.6.2-26.el7

Once you done this, you can use built in $PSVersionTable to confirm that its working properly:

Checking for PowerShell core version on CentOS
Checking for PowerShell core version on CentOS

Or you can also use which command in linux to check if its installed. To get back to bash/login shell, type exit from PowerShell prompt.

Also, even if this is an alpha release, tab completion for cmdlet works. Intellisense works in more or less the same way as linux distributions. For example, if you type Get-ChildItem – and then press tab for getting parameters, nothing comes out. But if you press tab twice, it will list all parameters. Again, if you type the partial name of parameter, press tab twice to list it:

Tab completion for parameters in PowerShell Core
Tab completion for parameters in PowerShell Core

2 thoughts on “Install PowerShell Core on Ubuntu / CentOS using package management

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s