PowerShell is Microsoft’s cross-platform scripting framework that now runs on Linux, including Ubuntu. While originally built for Windows, PowerShell works identically on Ubuntu, macOS, and Windows, letting you use the same scripts and automation tools across all your systems. Additionally, this makes PowerShell valuable for managing hybrid environments, automating Azure resources, or applying Windows administration skills to Linux systems. This guide walks through how to install PowerShell on Ubuntu 22.04 LTS and 24.04 LTS using Microsoft’s official repository.
Update Ubuntu Before PowerShell Installation
Before installing, update your system to ensure all packages are up-to-date. Therefore, this helps avoid any conflicts during the installation. Subsequently, open a terminal and run this command:
sudo apt update
Once the update completes, upgrade any outdated packages:
sudo apt upgrade
Add Microsoft PowerShell Repository
Import the GPG Key
Microsoft provides a GPG-signed repository to ensure you always get the latest official PowerShell releases. First, download and import the GPG key using curl. Then, add the repository configuration:
curl -fSsL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor | sudo tee /usr/share/keyrings/powershell.gpg > /dev/null
Add the Repository Configuration
Following the GPG key import, use the modern DEB822 format. The following command automatically detects your Ubuntu version and configures the repository correctly:
cat <<'EOF' | sudo tee /etc/apt/sources.list.d/powershell.sources
Types: deb
URIs: https://packages.microsoft.com/ubuntu/$(lsb_release -cs)/prod
Suites: $(lsb_release -cs)
Components: main
Architectures: $(dpkg --print-architecture)
Signed-By: /usr/share/keyrings/powershell.gpg
EOF
Note that Ubuntu automatically supports this modern format:
Microsoft’s PowerShell repository officially supports Ubuntu 22.04 LTS and 24.04 LTS only. Both versions fully support the .sources format shown above. Interim releases and older LTS versions are not supported by Microsoft’s repository.
Refresh the Package List
Following the repository configuration, refresh your package list to make PowerShell available for installation:
sudo apt update
Finalize PowerShell Installation via APT Command
With everything in place, install PowerShell:
sudo apt install powershell
Verify PowerShell Installation
With the installation complete, verify that PowerShell works correctly by launching a new PowerShell instance:
pwsh
Once you run the command, PowerShell will start and display the prompt PS> at the beginning of each line, confirming successful installation. Your terminal will now accept PowerShell cmdlets and scripts:
PowerShell 7.4.1 Copyright (c) Microsoft Corporation. PS>

Now that you have confirmed the successful installation of PowerShell, you can use it to manage your system, run scripts, and execute commands just like you would on a Windows system.
Essential PowerShell Commands
To exit PowerShell and return to your Ubuntu terminal, type:
exit
Beyond basic operations, PowerShell includes comprehensive built-in help. To access it, use the Get-Help cmdlet followed by a command name, or type help for an overview. For cross-platform PowerShell documentation covering all common cmdlets, visit the official PowerShell documentation.
Common PowerShell Tasks on Ubuntu
PowerShell cmdlets follow a Verb-Noun naming convention that makes commands predictable and discoverable. Below are core operations that work identically across Windows, Linux, and macOS.
List Files and Directories
To start, display directory contents using Get-ChildItem, which functions like ls in Bash:
Get-ChildItem
The output displays files and directories in your current location:
Directory: /home/user Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 11/23/2025 2:45 PM Desktop d---- 11/23/2025 1:30 PM Documents d---- 11/22/2025 4:12 PM Downloads -a--- 11/20/2025 10:22 AM 2048 notes.txt
Alternatively, for a recursive listing including hidden files:
Get-ChildItem -Recurse -Force
View System Information
Check running processes with detailed information:
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
The output displays the top 10 processes consuming CPU resources:
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
124 345.2 567.8 45.23 4521 0 firefox
89 234.5 412.3 28.17 3847 0 chrome
56 178.9 289.4 12.45 2934 0 powershell
42 112.3 201.5 8.92 2156 0 dotnet
38 95.6 167.2 6.34 1987 0 code
As you can see, this command sorts processes by CPU usage and displays the top 10 consumers, thereby demonstrating PowerShell’s pipeline capabilities for filtering and formatting output.
Read and Search File Content
Next, read file contents and search for specific patterns:
Get-Content /var/log/syslog | Select-String "error"
The output shows all lines containing “error” with line numbers and context:
/var/log/syslog:127:[WARN] USB device error detected /var/log/syslog:243:[ERROR] Failed to load kernel module /var/log/syslog:456:[ERROR] Authentication failure for user root /var/log/syslog:789:[WARN] Memory error rate elevated
Similar to Linux grep functionality, PowerShell’s Select-String cmdlet works like grep, making it familiar to Linux users while maintaining cross-platform script compatibility.
File Operations
Copy files with verbose output to track operations:
Copy-Item -Path ~/Documents/file.txt -Destination ~/Backup/ -Verbose
In contrast, you can remove files matching a pattern using:
Remove-Item ~/Downloads/*.tmp
Create Cross-Platform Scripts
Finally, understand how PowerShell scripts run identically on Ubuntu, Windows, and macOS. Below is an example that checks disk space across platforms:
Get-PSDrive -PSProvider FileSystem | Select-Object Name, Used, Free
On Ubuntu, the output shows mounted filesystems with usage information:
Name Used Free ---- ---- ---- / 128849952768 121932398592 /home 268435456000 242987654321
On Windows, the same command would display C:, D:, and other drive letters instead. Notably, the same command works on Windows (showing C:, D:) and Linux (showing root, home) without modification, illustrating PowerShell’s abstraction of platform-specific differences.
PowerShell Maintenance: Update and Remove
Like any software, PowerShell requires periodic maintenance. Below are common tasks to keep it updated or remove it entirely:
Update PowerShell
To keep PowerShell current, update it to the latest version by running the standard Ubuntu update command:
sudo apt update && sudo apt upgrade
Uninstall PowerShell
Conversely, if you need to remove PowerShell and its repository, execute these commands in order:
sudo apt remove powershell
sudo rm /etc/apt/sources.list.d/powershell.sources
sudo rm /usr/share/keyrings/powershell.gpg
Conclusion
Ultimately, PowerShell on Ubuntu delivers consistent scripting and automation across Windows, Linux, and macOS environments. Your installation provides access to the same cmdlets and modules you use on Windows, enabling cross-platform script portability, Azure resource management from Linux, and unified automation workflows. The modern repository configuration ensures automatic updates alongside your regular Ubuntu maintenance, keeping PowerShell current with the latest features and security patches from Microsoft.
Useful Links
Here is a valuable link related to using PowerShell:
- PowerShell Documentation: Access comprehensive documentation, including tutorials and reference materials, for detailed guides on installing, configuring, and using PowerShell.