PowerShell is a cross-platform command-line shell and scripting language developed by Microsoft. It can be used on a variety of operating systems, including Linux. This blog entry will walk you through the steps of installing PowerShell on Red Hat Enterprise Linux (RHEL) 7, 8, and 9.
Installing PowerShell on RHEL 7:
Step 1: Import the Microsoft GPG key To install PowerShell on RHEL 7, you need to first import the Microsoft GPG key. This key is used to verify the authenticity of the software packages you will download. Run the following command in the Terminal to import the key:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Step 2: Add the Microsoft package repository Next, you need to add the Microsoft package repository to your system. This repository contains the software packages you will need to install PowerShell. Run the following command in the Terminal to add the repository:
sudo curl -o /etc/yum.repos.d/microsoft.repo https://packages.microsoft.com/config/rhel/7/prod.repo
Step 3: Install PowerShell Now that the Microsoft package repository is added, you can install PowerShell by running the following command in the Terminal:
sudo yum install -y powershell
Once the installation is complete, you can launch PowerShell by running the following command in the Terminal:
pwsh
Installing PowerShell on RHEL 8 and 9:
Step 1: Import the Microsoft GPG key To install PowerShell on RHEL 8 and 9, you need to first import the Microsoft GPG key. Run the following command in the Terminal to import the key:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Step 2: Add the Microsoft package repository Next, you need to add the Microsoft package repository to your system. Run the following command in the Terminal to add the repository:
sudo curl -o /etc/yum.repos.d/microsoft.repo https://packages.microsoft.com/config/rhel/8/prod.repo
For RHEL 9, run the following command instead:
sudo curl -o /etc/yum.repos.d/microsoft.repo https://packages.microsoft.com/config/rhel/9/prod.repo
Step 3: Install PowerShell Now that the Microsoft package repository is added, you can install PowerShell by running the following command in the Terminal:
sudo dnf install -y powershell
For RHEL 9, run the following command instead:
sudo yum install -y powershell
Once the installation is complete, you can launch PowerShell by running the following command in the Terminal:
pwsh
In conclusion, PowerShell can be easily installed on RHEL 7, 8, and 9 by following these simple steps. By installing PowerShell, you can take advantage of its many features and capabilities to simplify and automate tasks on your RHEL system.