How To

Install PowerShell on RHEL 10 / Rocky Linux 10 / AlmaLinux 10

PowerShell is Microsoft’s cross-platform task automation tool that combines a command-line shell with a scripting language. Originally built for Windows, PowerShell 7 runs natively on Linux and is fully open source. If you manage mixed Linux and Windows environments, having PowerShell on your Linux servers lets you run the same scripts and modules across both platforms without translation. It is also useful for automating Azure and Microsoft 365 resources directly from your RHEL workstation.

Original content from computingforgeeks.com - post 16777

This guide walks you through installing PowerShell 7.6 on RHEL 10, Rocky Linux 10, AlmaLinux 10, and Fedora 42. We cover three installation methods – the Microsoft package repository, a standalone RPM, and a manual tar.gz install that requires no root access. After installation, we go through basic usage, scripting, and SSH-based remoting.

Prerequisites

Before you begin, make sure you have the following in place:

  • A running RHEL 10, Rocky Linux 10, AlmaLinux 10, or Fedora 42 system
  • A user account with sudo privileges (or root access)
  • An active internet connection to download packages
  • curl installed (available by default on all supported distributions)

Update your system packages before proceeding:

sudo dnf update -y

Step 1: Install PowerShell from Microsoft Repository

The recommended way to install PowerShell on RHEL-based distributions is through Microsoft’s official package repository. This method gives you automatic updates through dnf and handles all dependencies.

First, download and install the Microsoft repository configuration package. This registers the packages.microsoft.com repository on your system:

curl -sSL -O https://packages.microsoft.com/config/rhel/9/packages-microsoft-prod.rpm
sudo rpm -i packages-microsoft-prod.rpm
rm packages-microsoft-prod.rpm

Note: At the time of writing, Microsoft provides repository packages for RHEL 8 and RHEL 9. The RHEL 9 repository works on RHEL 10, Rocky Linux 10, AlmaLinux 10, and Fedora 42 since the packages are compatible. If Microsoft releases a dedicated RHEL 10 repo package, switch to https://packages.microsoft.com/config/rhel/10/packages-microsoft-prod.rpm instead.

Now update the package index and install PowerShell:

sudo dnf update
sudo dnf install powershell -y

The dnf output confirms a successful installation:

Installed:
  powershell-7.6.0-1.rh.x86_64

Complete!

Step 2: Install PowerShell via .rpm Package (Alternative)

If you prefer not to add the Microsoft repository to your system, you can download and install the RPM package directly from the PowerShell GitHub releases page. This is a single command that downloads and installs in one step:

sudo dnf install -y https://github.com/PowerShell/PowerShell/releases/download/v7.6.0/powershell-7.6.0-1.rh.x86_64.rpm

This method installs the same PowerShell package but does not configure automatic updates. You will need to manually download and install new RPM packages when updates are released.

Step 3: Install PowerShell via .tar.gz (Manual, No Root Needed)

The tar.gz method is ideal when you do not have root access or want to run PowerShell from your home directory without touching system packages. This is common on shared servers or development environments where you cannot install system-wide packages.

Download the Linux x64 tar.gz archive and extract it to a local directory:

curl -sSL -o /tmp/powershell-7.6.0-linux-x64.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.6.0/powershell-7.6.0-linux-x64.tar.gz
mkdir -p ~/powershell
tar -xzf /tmp/powershell-7.6.0-linux-x64.tar.gz -C ~/powershell
rm /tmp/powershell-7.6.0-linux-x64.tar.gz

Make the PowerShell binary executable and add it to your PATH so you can run pwsh from anywhere:

chmod +x ~/powershell/pwsh
echo 'export PATH="$HOME/powershell:$PATH"' >> ~/.bashrc
source ~/.bashrc

After sourcing your shell configuration, the pwsh command is available in your terminal session.

Step 4: Verify Installation

Regardless of which installation method you used, verify that PowerShell is working by checking the version:

pwsh --version

You should see the installed version in the output:

PowerShell 7.6.0

Launch an interactive PowerShell session to confirm everything works:

pwsh

You are now in the PowerShell shell, indicated by the PS prompt prefix. Run a quick test to see detailed version information:

$PSVersionTable

This displays comprehensive version details:

Name                           Value
----                           -----
PSVersion                      7.6.0
PSEdition                      Core
GitCommitId                    7.6.0
OS                             Linux 6.12.0 #1 SMP x86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Type exit to return to your regular bash shell.

Step 5: Basic PowerShell Usage on Linux

If you are coming from a Bash background, PowerShell will feel different at first. Commands in PowerShell are called cmdlets and follow a Verb-Noun naming convention. The good news is that many common Linux commands work in PowerShell through built-in aliases.

File System Navigation

PowerShell supports familiar navigation commands. Start a PowerShell session with pwsh and try these:

Get-Location
Set-Location /etc
Get-ChildItem
Get-ChildItem -Recurse -Filter "*.conf" | Select-Object -First 10

The shortcuts cd, ls, and pwd also work in PowerShell since they are aliases for Set-Location, Get-ChildItem, and Get-Location.

Working with Files

Reading and writing files in PowerShell uses cmdlets that handle encoding and line endings consistently:

Get-Content /etc/hostname
Get-Content /etc/os-release | Select-String "PRETTY_NAME"
"Hello from PowerShell on Linux" | Out-File ~/test.txt
Get-Content ~/test.txt

Process and Service Management

PowerShell can interact with Linux processes and systemd services:

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
Get-Process -Name sshd
Stop-Process -Name myapp -Force

For systemd services, you can call native Linux commands from within PowerShell:

systemctl status sshd
systemctl list-units --type=service --state=running

Working with JSON and REST APIs

One area where PowerShell excels on Linux is parsing structured data. You can query REST APIs and work with JSON natively without piping through jq:

$response = Invoke-RestMethod -Uri "https://api.github.com/repos/PowerShell/PowerShell/releases/latest"
$response.tag_name
$response.published_at
$response.assets | Select-Object name, size, download_count | Format-Table

Step 6: Run PowerShell Scripts

PowerShell scripts use the .ps1 extension. You can create and run scripts directly on your Linux system. Here is a practical example that checks disk usage and warns about partitions running low on space.

Create a script file:

echo '# Disk usage check script
$threshold = 80

$diskInfo = df -h --output=target,pcent | Select-Object -Skip 1
foreach ($line in $diskInfo) {
    $parts = $line.Trim() -split "\s+"
    if ($parts.Count -ge 2) {
        $mount = $parts[0]
        $usage = [int]($parts[1] -replace "%","")
        if ($usage -ge $threshold) {
            Write-Warning "HIGH USAGE: $mount is at ${usage}%"
        } else {
            Write-Output "OK: $mount is at ${usage}%"
        }
    }
}' > ~/check-disk.ps1

Run the script with pwsh:

pwsh -File ~/check-disk.ps1

Expected output on a typical system:

OK: / is at 42%
OK: /boot is at 28%
OK: /home is at 15%

You can also run one-liner PowerShell commands directly from bash without entering an interactive session:

pwsh -Command "Get-Process | Where-Object {$_.CPU -gt 100} | Format-Table Name, CPU, Id"

To schedule PowerShell scripts with cron, add an entry like this:

crontab -e

Add the following line to run the disk check script daily at 8 AM:

0 8 * * * /usr/bin/pwsh -File /root/check-disk.ps1 >> /var/log/disk-check.log 2>&1

Step 7: PowerShell Remoting (SSH-Based)

PowerShell remoting over SSH lets you run PowerShell commands on remote Linux and Windows machines. Unlike WinRM-based remoting, SSH remoting works natively on Linux without additional configuration on the transport layer.

Configure the Remote Host

On the remote machine where you want to accept PowerShell remoting connections, add a PowerShell subsystem to the SSH server configuration:

echo 'Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile' | sudo tee -a /etc/ssh/sshd_config

Restart the SSH service to apply the change:

sudo systemctl restart sshd

Connect from the Local Machine

From your local PowerShell session, establish a remoting connection to the configured host:

$session = New-PSSession -HostName 192.168.1.100 -UserName admin -SSHTransport
Invoke-Command -Session $session -ScriptBlock {
    $PSVersionTable
    Get-Process | Select-Object -First 5
    hostname
}
Remove-PSSession $session

You can also start an interactive remote session:

Enter-PSSession -HostName 192.168.1.100 -UserName admin -SSHTransport

This gives you a live PowerShell prompt on the remote machine. Type Exit-PSSession to disconnect.

For more details on installation options and supported platforms, see the official Microsoft PowerShell installation guide for RHEL.

PowerShell vs Bash – Quick Reference

If you are a Bash user picking up PowerShell, this table maps common operations between the two shells:

TaskBashPowerShell
List filesls -laGet-ChildItem -Force
Current directorypwdGet-Location
Change directorycd /pathSet-Location /path
Read filecat file.txtGet-Content file.txt
Find text in filesgrep "text" fileSelect-String "text" file
Count lineswc -l file(Get-Content file).Count
List processesps auxGet-Process
Kill processkill -9 PIDStop-Process -Id PID -Force
Environment variableecho $HOME$env:HOME
Set variableVAR="value"$VAR = "value"
Pipe and filtercmd | grep textcmd | Where-Object {$_ -match "text"}
Download filecurl -O urlInvoke-WebRequest -Uri url -OutFile file
Parse JSONjq '.key' file.json(Get-Content file.json | ConvertFrom-Json).key
Loopfor i in 1 2 3; do echo $i; done1..3 | ForEach-Object { $_ }

Conclusion

You now have PowerShell 7.6 installed on your RHEL 10, Rocky Linux 10, AlmaLinux 10, or Fedora 42 system. The Microsoft repository method is best for production servers that need automatic updates, while the tar.gz method works well for development machines or when you lack root access. PowerShell’s object-oriented pipeline and built-in JSON handling make it a strong complement to Bash, especially when managing mixed Linux and Windows infrastructure or working with Azure and Microsoft 365 APIs.

Related Articles

AlmaLinux How To Install MariaDB 11 on Rocky Linux 9 / AlmaLinux 9 CentOS Install Java 8 on CentOS 8 / RHEL 8 / Rocky Linux 8 MySQL Install MS SQL Server 2019 on Rocky 8 / AlmaLinux 8 AlmaLinux Troubleshoot SELinux on Rocky Linux 10 / AlmaLinux 10 / RHEL 10

Leave a Comment

Press ESC to close