Install PowerShell on Ubuntu 24.04

Install PowerShell on Ubuntu 24.04

PowerShell is an open-source shell program from Microsoft for automation and configuration management. Unlike traditional command prompts, it works with objects rather than plain text, allowing administrators and developers to efficiently manage systems, automate repetitive tasks, and interact with APIs or services. This tutorial explains how to install PowerShell on Ubuntu 24.04.

Install PowerShell

Get the latest release number of PowerShell from its GitHub repository:

POWERSHELL_VERSION=$(curl -s "https://api.github.com/repos/PowerShell/PowerShell/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')

Download the PowerShell Debian package from releases page:

wget -qO powershell.deb https://github.com/PowerShell/PowerShell/releases/latest/download/powershell_${POWERSHELL_VERSION}-1.deb_amd64.deb

Install the downloaded package using APT:

sudo apt install -y ./powershell.deb

We can check PowerShell version as follows:

pwsh --version

Remove the downloaded package file:

rm -rf powershell.deb

Testing PowerShell

Verify that PowerShell is working as expected by running a simple command:

pwsh -Command 'Write-Output "Hello world"'

This command should print Hello world in the terminal.

Uninstall PowerShell

If you want to completely remove PowerShell, run the following command:

sudo apt purge --autoremove -y powershell

Delete PowerShell cache and configuration files:

rm -rf ~/.cache/powershell ~/.local/share/powershell

Leave a Comment

Cancel reply

Your email address will not be published.