Cyberithub

How to Install PowerShell on RHEL/CentOS 7 [Easy Steps]

Advertisements

In this article, I will take you through the steps to install PowerShell on RHEL/CentOS 7. If you have worked on Windows operating system then you might be aware of PowerShell. It is known as the successor of Windows traditional Command line processor which is available since its first release in December 1987. PowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS.

Sometimes, when developers and programmers who has been using PowerShell from long time switch their base operating system from Windows to Linux, initially they find it difficult to work on as they have to learn all the Linux tools and utilities. So for all those professionals installing PowerShell in Linux will help them work much faster and with ease. The other benefits PowerShell utility is in terms of migrating PowerShell Scripts from Windows to Linux. Similarly, there are other benefits as well which we will understand in future articles. But for the moment we will see the steps to install PowerShell on RHEL/CentOS 7 Systems in great detail.

How to Install PowerShell on RHEL/CentOS 7 [Easy Steps]

How to Install PowerShell on RHEL/CentOS 7 

Also Read: How to Install and Use AIDE on RHEL/CentOS 7/8 [Easy Steps]

Step 1: Prerequisites

a) You should have a running RHEL/CentOS 7 System.

b) You should have sudo or root access to run privileged commands.

c) You should have yum utility available in your System.

 

Step 2: Update Your Server

Before installing a new package, it is always a good idea to update the System with the latest available versions using yum update command as shown below. If any of the packages needs upgradation then upgrade it by using yum upgrade command.

[root@cyberithub ~]# yum update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirror.snu.edu.in
* extras: centos.mirror.snu.edu.in
* updates: centos.mirror.snu.edu.in
No packages marked for update

 

Step 3: Add Repo

You can visit Microsoft Official Download page and check the steps to add the repo on CentOS 7.

[root@cyberithub ~]# curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 193 100 193 0 0 248 0 --:--:-- --:--:-- --:--:-- 248
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/7/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc

 

Step 4: Update Package Cache

Next step is to update the package cache with all the package information from the newly added repo using yum update command.

[root@cyberithub ~]# yum update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirror.snu.edu.in
* extras: centos.mirror.snu.edu.in
* updates: centos.mirror.snu.edu.in
packages-microsoft-com-prod | 3.0 kB 00:00:00
packages-microsoft-com-prod/primary_db | 531 kB 00:00:00
No packages marked for update

 

Step 5: Install PowerShell

Now that you have the repo added and enabled, PowerShell can be installed along with all its dependencies using yum install -y powershell command as shown below.

[root@cyberithub ~]# yum install -y powershell
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirror.snu.edu.in
* extras: centos.mirror.snu.edu.in
* updates: centos.mirror.snu.edu.in
Resolving Dependencies
--> Running transaction check
---> Package powershell.x86_64 0:7.2.1-1.rh will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Installing:
powershell x86_64 7.2.1-1.rh packages-microsoft-com-prod 66 M

Transaction Summary
=============================================================================================================================================================
Install 1 Package

Total download size: 66 M
Installed size: 184 M
...............................................................

 

Step 6: Check Version

After successful installation of PowerShell utility, you can check its version by using pwsh --version command as shown below.

[root@cyberithub ~]# pwsh --version
PowerShell 7.2.1

 

Step 7: Start PowerShell

To start PowerShell prompt, you need to run pwsh command as shown below. This will open a prompt where you can start using the PowerShell commands.

[root@cyberithub ~]# pwsh
PowerShell 7.2.1
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /root>

 

Step 8: Check all the Commands

To check all the commands and modules available in the System, you need to use Get-Command as shown below.

PS /root> Get-Command

CommandType   Name                               Version     Source
-----------   ----                               -------     ------
Function      cd..
Function      cd\
Function      Clear-Host
Function      Compress-Archive                    1.2.5      Microsoft.PowerShell.Archive
Function      Expand-Archive                      1.2.5      Microsoft.PowerShell.Archive
Function      Find-Command                        2.2.5      PowerShellGet
Function      Find-DSCResource                    2.2.5      PowerShellGet
Function      Find-Module                         2.2.5      PowerShellGet
Function      Find-RoleCapability                 2.2.5      PowerShellGet
Function      Find-Script                         2.2.5      PowerShellGet
Function      Get-CredsFromCredentialProvider     2.2.5      PowerShellGet

 

Step 9: Check Timezone

To check the current setup timezone, you need to run Get-Timezone command as shown below.

PS /root> Get-Timezone

Id : America/New_York
HasIanaId : True
DisplayName : (UTC-05:00) Eastern Time (New York)
StandardName : Eastern Standard Time
DaylightName : Eastern Daylight Time
BaseUtcOffset : -05:00:00
SupportsDaylightSavingTime : True

 

Step 10: Check all the Process

To check all the current running process in the System, you need to use Get-process command as shown below.

PS /root> Get-process

NPM(K) PM(M) WS(M) CPU(s) Id    SI    ProcessName
------ ----- ----- ------ --    --    -----------
0      0.00  16.30 0.06   2752  …04   abrt-applet
0      0.00  4.72  0.04   702   702   abrt-watch-log
0      0.00  5.53  0.02   701   701   abrtd
0      0.00  3.93  0.07   699   699   accounts-daemon
0      0.00  1.47  0.01   703   703   alsactl
0      0.00  3.59  0.00   2350  …14   at-spi-bus-launcher
0      0.00  3.85  0.01   2360  …14   at-spi2-registryd
0      0.00  0.00  0.00   280   0     ata_sff
0      0.00  0.91  0.00   1142  …42   atd
0      0.00  0.79  0.02   670   670   audispd

 

Step 11: Uninstall PowerShell

Once you are done using PowerShell, you can uninstall it by using yum remove powershell command as shown below.

[root@cyberithub ~]# yum remove powershell
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package powershell.x86_64 0:7.2.1-1.rh will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Removing:
powershell x86_64 7.2.1-1.rh @packages-microsoft-com-prod 184 M

Transaction Summary
=============================================================================================================================================================
Remove 1 Package

Installed size: 184 M
Is this ok [y/N]: y
................................................................

Leave a Comment