Install PowerShell on AlmaLinux 9 and RHEL 9: Powerful Command Line Shell
This tutorial, brought to you by Orcacore, guides you through the process of installing PowerShell on AlmaLinux 9 and RHEL 9. PowerShell is a versatile command-line shell and scripting language, invaluable for IT professionals for system configuration and automation of administrative tasks. Knowing how to Install PowerShell on AlmaLinux 9 and RHEL 9 is a valuable skill.
Before you begin to Install PowerShell on AlmaLinux 9 and RHEL 9, ensure you have access to your server as a non-root user with sudo
privileges. If you need assistance with this, refer to the "Initial Server Setup with AlmaLinux 9" guide.
This guide demonstrates two methods for installing PowerShell:
- Installation via GitHub
- Installation using Snapd
Let’s dive into the steps to Install PowerShell on AlmaLinux 9 and RHEL 9.
Run System Update on AlmaLinux 9 / RHEL 9
Regardless of the installation method you choose, it’s crucial to update your local package index first. Execute the following command:
sudo dnf update -y
After the update completes, proceed to the next step.
Method 1. PowerShell Installation Via GitHub on AlmaLinux 9 / RHEL 9
PowerShell offers broad Linux distribution support, with the latest packages available on GitHub.
To install, locate the most recent .rpm
package and use the following command, replacing the version number with the latest available:
sudo dnf install https://github.com/PowerShell/PowerShell/releases/download/v7.3.4/powershell-7.3.4-1.rh.x86_64.rpm
Once the installation finishes, verify it by typing:
pwsh
You should see output similar to this:
**<mark>Output</mark>**
PowerShell 7.3.4
PS /root>
To exit PowerShell, simply type:
PS /root> exit
Method 2. PowerShell Installation with Snapd on AlmaLinux 9 / RHEL 9
Another approach involves using the Snap package manager. First, install the EPEL (Extra Packages for Enterprise Linux) repository:
sudo dnf install epel-release -y
Next, install the Snap packages themselves:
sudo dnf install snapd -y
Enable and start the snapd
service:
# sudo systemctl enable --now snapd.socket
# sudo systemctl start --now snapd.socket
Enable classic snap support by creating a symbolic link:
sudo ln -s /var/lib/snapd/snap /snap
Restart your session:
reboot
After logging back in, use Snap to Install PowerShell on AlmaLinux 9 and RHEL 9:
sudo snap install powershell --classic
Verify the installation by typing:
pwsh
The output should be similar to:
**<mark>Output</mark>**
PowerShell 7.3.4
**PS /root>**
Step 4 – PowerShell Commands on Linux
To explore available PowerShell commands, type:
**PS /root>** Get-Command
This will produce a list of commands:
**<mark>Output</mark>**
CommandType Name Version S
o
u
r
c
e
----------- ---- ------- -
Function cd..
Function cd
Function Clear-Host
Function Compress-Archive 1.2.5 M
Function exec
Function Expand-Archive 1.2.5 M
Function Find-Command 2.2.5 P
Function Find-DSCResource 2.2.5 P
Function Find-Module 2.2.5 P
Function Find-RoleCapability 2.2.5 P
Function Find-Script 2.2.5 P
Function Get-CredsFromCredentialProvider 2.2.5 P
Function Get-InstalledModule 2.2.5 P
Function Get-InstalledScript 2.2.5 P
Function Get-PSRepository 2.2.5 P
Function help
Function Install-Module 2.2.5 P
Function Install-Script 2.2.5 P
Function New-ScriptFileInfo 2.2.5 P
Function oss
Function Pause
Function prompt
....
For comprehensive information, refer to the PowerShell Docs.
Conclusion
You’ve successfully learned how to Install PowerShell on AlmaLinux 9 and RHEL 9 using both GitHub and Snapd. Enjoy leveraging PowerShell on your Linux distribution.
You may also be interested in these articles:
- How To Install Java with DNF on AlmaLinux 9
- Set Up NFS Server and Client on AlmaLinux 9
- How To Install GitHub Desktop on AlmaLinux 9
Alternative Installation Methods for PowerShell on AlmaLinux 9 and RHEL 9
While the above methods are common, here are two alternative approaches to installing PowerShell on AlmaLinux 9 and RHEL 9:
1. Using Microsoft’s Official Package Repositories
Microsoft provides official package repositories for PowerShell. This ensures you receive updates directly from Microsoft and can be a more reliable approach than relying solely on GitHub or Snapd.
Steps:
-
Register the Microsoft repository:
First, you need to register the Microsoft repository. This involves downloading and installing the Microsoft GPG key and creating a repository configuration file.
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Next, create the repository file. This file tells your system where to find the PowerShell packages. The location of this file varies based on RHEL/AlmaLinux version.
For RHEL/AlmaLinux 9, create the file
/etc/yum.repos.d/powershell.repo
with the following content:[powershell-microsoft.com] name=powershell-microsoft.com baseurl=https://packages.microsoft.com/yumrepos/powershell-microsoft.com-rhel-9/ gpgcheck=true gpgkey=https://packages.microsoft.com/keys/microsoft.asc enabled=1
-
Install PowerShell:
Now that the repository is configured, you can install PowerShell using
dnf
:sudo dnf install powershell -y
-
Verify the installation:
As before, verify the installation by running:
pwsh
Advantages:
- Direct updates from Microsoft.
- Potentially more stable than community-maintained packages.
- Standardized installation method.
Disadvantages:
- Requires manual repository configuration.
- Relies on Microsoft maintaining the repository.
2. Installing from a Container (Docker/Podman)
Another powerful option is to run PowerShell within a container using Docker or Podman. This isolates PowerShell from the host system and simplifies dependency management.
Steps:
-
Install Docker or Podman:
If you don’t have Docker or Podman installed, install one of them. For Podman:
sudo dnf install podman -y sudo systemctl enable --now podman.socket
-
Pull the PowerShell Docker image:
Microsoft provides official PowerShell Docker images. Pull the latest image:
sudo podman pull mcr.microsoft.com/powershell
-
Run the PowerShell container:
Run the container in interactive mode:
sudo podman run -it mcr.microsoft.com/powershell
This will start a new PowerShell session within the container. You might want to mount a volume to share files between your host system and the container. For example, to mount the
/home/<user>
directory:sudo podman run -it -v /home/<user>:/home/<user> mcr.microsoft.com/powershell
Replace
<user>
with your actual username.
Advantages:
- Isolation from the host system.
- Consistent environment across different systems.
- Simplified dependency management.
- Easy to update and revert versions.
Disadvantages:
- Requires familiarity with container technology.
- Potentially higher resource usage compared to native installation.
- Requires volume mounting for persistent data.
By exploring these alternative methods, you can choose the installation approach that best suits your specific needs and environment when you Install PowerShell on AlmaLinux 9 and RHEL 9. Each method offers a unique set of advantages and disadvantages, providing flexibility for diverse use cases.