How to install PowerShell 7 and essential tools on Linux
As you prepare for the OnRamp track at the PowerShell + DevOps Global Summit, this guide walks you through installing the essential tools on your Ubuntu Linux system if that's your preferred operating system. You'll learn to install PowerShell version 7, Visual Studio Code, and the PowerShell extension for VS Code to ensure your system is prepared for the event.
If you're using Windows 11 or macOS, refer to the companion articles in this series:
- How to install PowerShell 7 and essential tools on Windows 11
- How to install PowerShell 7 and essential tools on macOS
Prerequisites
All installation methods in this article require an active internet connection.
Before beginning the installation, make sure your Linux distribution is up-to-date. Open your terminal and run the following commands:
1sudo apt update && sudo apt upgrade
These commands update your package lists and upgrade all your installed packages to their latest versions.
Install PowerShell version 7
Several guides recommend installing PowerShell 7 on Ubuntu using the Snap package manager. However, PowerShell isn't available for all architectures using this method. For example, if you try installing PowerShell on an arm64 system, you'll encounter the following error:
"snap 'powershell' isn't available on stable for this architecture (arm64), but it's available for other architectures like amd64".
Trying to install with the apt
package manager using the universal Debian package also fails on arm64 systems.
To avoid these issues, you can install PowerShell 7 using the following script, which works universally on any architecture.
1#!/bin/bash 2 3# Determine the system architecture 4ARCH=$(dpkg --print-architecture) 5 6# Get the latest PowerShell version number 7pwshVersion=$(curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep 'tag_name' | cut -d '"' -f 4 | sed 's/v//') 8 9# Download PowerShell tarball for the detected architecture and version 10downloadUrl="https://github.com/PowerShell/PowerShell/releases/download/v$pwshVersion/powershell-$pwshVersion-linux-$ARCH.tar.gz" 11curl -L -o /tmp/powershell.tar.gz "$downloadUrl" 12 13# Create the installation directory if it doesn't exist 14sudo mkdir -p /opt/microsoft/powershell/7 15 16# Extract the tarball to the installation directory 17sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7 18 19# Make pwsh executable 20sudo chmod +x /opt/microsoft/powershell/7/pwsh 21 22# Remove the existing symlink if one exists 23sudo rm "/usr/bin/pwsh" 24 25# Create a new symlink for pwsh 26sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh 27 28# Clean up by removing the downloaded tarball 29rm /tmp/powershell.tar.gz
After installation, verify that PowerShell 7 is installed correctly by running:
1pwsh
You should see the PowerShell prompt, indicating that the installation was successful.
Determine your PowerShell version
Now that you installed PowerShell version 7, the remainder of this article assumes you're using PowerShell. Use the $PSVersionTable
automatic variable to determine your current version of PowerShell and to ensure you're using PowerShell:
1$PSVersionTable.PSVersion
To determine if you have the latest stable version of PowerShell 7, compare your version to the newest release by running:
1$Uri = 'https://api.github.com/repos/powershell/powershell/releases/latest' 2Invoke-RestMethod -Uri $Uri | Select-Object -ExpandProperty tag_name
Install Visual Studio Code (VS Code)
Visual Studio Code (VS Code) is a lightweight, cross-platform code editor ideal for PowerShell development and scripting. It offers syntax highlighting, debugging, version control, and a rich extension ecosystem.
You only need to install VS Code on the machine where you develop PowerShell scripts and tools.
1#!/bin/bash 2 3# Install necessary packages 4sudo apt install -y wget gpg 5 6# Download and store Microsoft's GPG key 7wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg 8sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/ 9 10# Detect system architecture (amd64, arm64, etc.) 11ARCH=$(dpkg --print-architecture) 12 13# Add the VS Code repository based on the detected architecture 14sudo sh -c "echo 'deb [arch=$ARCH] https://packages.microsoft.com/repos/vscode stable main' > /etc/apt/sources.list.d/vscode.list" 15 16# Update package lists and install Visual Studio Code 17sudo apt update 18sudo apt install -y code 19 20# Clean up 21rm -f packages.microsoft.gpg
Install the PowerShell extension for VS Code
Once VS Code is installed, you'll want to add the PowerShell extension to enhance your development environment.
The PowerShell extension for Visual Studio Code enhances the PowerShell development experience with features like IntelliSense, debugging, and integrated script analysis. It provides a comprehensive toolkit for writing, testing, and optimizing PowerShell scripts directly within VS Code.
1code --install-extension ms-vscode.powershell
Summary
This guide walked you through installing PowerShell 7 and essential tools on your Ubuntu Linux system. It focused on PowerShell, Visual Studio Code, and the PowerShell extension for VS Code. It provided step-by-step instructions on how to use a script for seamless installations on any architecture.
References
For other Linux distributions and additional installation methods, refer to the following resources: