Utilizing PowerShell, developers and IT professionals can unlock the power of automation. An open-source CLI tool with code lets users streamline their tasks and quickly configure settings. The following tutorial will teach you how to install PowerShell on Ubuntu 22.04 LTS Jammy Jellyfish or Ubuntu 20.04 Focal Fossa LTS. The tutorial will use the command line terminal with complete steps to install the official repository and tips on updating and removing the software securely and adequately.
Recommended Steps Before Installation
Before you begin, run an update on your system to ensure all packages are up-to-date to avoid any conflicts during the installation.
sudo apt update
Optionally, you can list the updates for users who require review or are curious.
sudo apt --list upgradable
Proceed to upgrade any outdated packages using the following command.
sudo apt upgrade
Install Required Packages
The following dependencies will need to be installed. Most of these packages would already be present on your system, but running the command can help ensure they’re installed.
sudo apt install dirmngr lsb-release ca-certificates software-properties-common apt-transport-https curl -y
First, you will need to import the GPG and the repository. Luckily this is straightforward, and you will always have the most up-to-date version available on your system.
Import the GPG key using the following command.
curl -fSsL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor | sudo tee /usr/share/keyrings/powershell.gpg > /dev/null
Next, import the repository with the following command that matches your Ubuntu distribution version.
First, Ubuntu 22.04 Jammy JellyFish LTS users must use the following command.
echo "deb [arch=amd64,armhf,arm64 signed-by=/usr/share/keyrings/powershell.gpg] https://packages.microsoft.com/ubuntu/22.04/prod/ jammy main" | sudo tee /etc/apt/sources.list.d/powershell.list
Secondly, Ubuntu 20.04 Focal Fossa LTS users must use the following command.
echo "deb [arch=amd64,armhf,arm64 signed-by=/usr/share/keyrings/powershell.gpg] https://packages.microsoft.com/ubuntu/20.04/prod/ focal main" | sudo tee /etc/apt/sources.list.d/powershell.list
Once done, run an APT update to reflect the new additional repository.
sudo apt update
Now you can install PowerShell using the following command.
sudo apt install powershell -y
Now that you have completed the installation to activate PowerShell, use the following command.
And that is it, and you have successfully installed the latest PowerShell.
PowerShell Commands Example
Now that you have logged into your terminal, some common examples of using PowerShell are as follows.
Detail PowerShell information
List a directory
Print previous command history
List process information
Exit PowerShell instance
Additional Commands & Tips
How to Update PowerShell
To check for updates using the command line, use the following command to allow a blanket check for any updates across all APT packages.
sudo apt update && sudo apt upgrade
How to Remove (Uninstall) PowerShell
When you no longer want PowerShell installed on your system, use the following command to remove it.
sudo apt autoremove powershell -y
Next, remove the repository using the following command.
sudo rm /etc/apt/sources.list.d/powershell.list
For good housekeeping and security, remove the GPG key as follows.
sudo rm /usr/share/keyrings/powershell.gpg
Microsoft PowerShell is a great way to save time and automate tedious tasks. More information about PowerShell and how to use it, amongst many other things, can be found in the official documentation.