Are you looking for steps to install Microsoft PowerShell on Ubuntu? Here’s how we do it.
Here at Bobcares, we have seen several such Ubuntu related queries as part of our Server Management Services for web hosts and online service providers.
Today, we’ll take a look at how to install Microsoft Powershell.
Know more about PowerShell
Powershell is a .net-based configuration management and automation tool.
Also, it is an open-source and cross-platform project that can be installed on Windows, macOS, and Linux.
It mainly performs tasks such as automation of repetitive jobs and configuration management. Moreover, it provides an interactive command-line shell and a scripting environment.
How we install Microsoft PowerShell on Ubuntu
Now let’s take a look at how our Support Engineers install the PowerShell.
1. Retrieve the Microsoft Repository GPG Keys
As a first step, we retrieve the Microsoft Repository GPG Keys by running the below command.
root@host [~]# cd /usr/src/
root@host:/usr/src# wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
2. Next, we install the Microsoft GPG Keys. For that, we use the dpkg command.
root@host:/usr/src# sudo dpkg -i packages-microsoft-prod.deb
Selecting previously unselected package packages-microsoft-prod.
(Reading database … 257148 files and directories currently installed.)
Preparing to unpack packages-microsoft-prod.deb …
Unpacking packages-microsoft-prod (1.0-ubuntu18.04.2) …
Setting up packages-microsoft-prod (1.0-ubuntu18.04.2) …
root@host:/usr/src#
3. Now, we shall update the repository list to ensure that we have the latest list of packages available.
root@host:/usr/src# apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu eoan InRelease
Hit:2 http://archive.canonical.com/ubuntu eoan InRelease
Get:3 http://security.ubuntu.com/ubuntu eoan-security InRelease [97.5 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu eoan-updates InRelease [97.5 kB]
Get:5 https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease [4,002 B]
Hit:6 http://archive.ubuntu.com/ubuntu eoan InRelease
Get:7 http://us.archive.ubuntu.com/ubuntu eoan-backports InRelease [88.8 kB]
…
…
…
Reading package lists… Done
root@host:/usr/src#
4. Usually, we can install Ubuntu software from multiple software repositories. But, in order to install Powershell, we must enable the universe repository. Here is the command for it.
add-apt-repository universe
5. Now, we install PowerShell. For that, we run the below command.
root@host:/usr/src# apt-get install -y powershell
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
liblttng-ust-ctl4 liblttng-ust0 liburcu6
The following NEW packages will be installed:
liblttng-ust-ctl4 liblttng-ust0 liburcu6 powershell
0 upgraded, 4 newly installed, 0 to remove and 42 not upgraded.
Need to get 57.7 MB of archives.
After this operation, 158 MB of additional disk space will be used.
root@host:/usr/src#
Make sure to enter ‘Y’ when asked for confirmation during the installation process.
6. Since, we have installed the PowerShell, we now run it. For that, we use the ‘pwsh’ command as shown below.
root@host:/usr/src# pwsh
PowerShell 6.2.4
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type ‘help’ to get help.
PS /usr/src>
Now the command prompt changes from
root@host:/usr/src#
to
PS /usr/src>
Uninstalling Powershell from Ubuntu
If you wish to uninstall the PowerShell then here is the command to uninstall it.
PS /usr/src> apt-get remove powershell
Install Microsoft PowerShell Using Snap on Ubuntu
For simple installation, the PowerShell Core for Linux is also published in the Snap store as well.
Here is the command that we use to install the PowerShell.
root@host:/usr/src# snap install powershell –classic
Before initiating the installation, Ubuntu requires to authenticate. So to proceed, enter the credentials.
After the authentication, the installation begins. After some time, a successful message is shown.
Once we successfully install PowerShell, we can now launch the PowerShell. For that, type ‘powershell’ in the terminal console and it will take you to PowerShell terminal in an instant.
powershell
Uninstall Using Snap from Ubuntu
Here is the command to remove Powershell using snap.
root@host:/usr/src# snap remove powershell
[Need any further assistance with Ubuntu queries? – We are here to help you.]
Conclusion
Today, we saw how our Support Engineers install PowerShell on Ubuntu, and also we saw how to uninstall it.
0 Comments