PowerShell on Linux brings the same scripting language and object-oriented pipeline that Windows administrators rely on to your Debian server or workstation. You can automate user provisioning, parse structured log files, query REST APIs and pipe the JSON directly into further processing, or manage remote machines over SSH without learning a separate toolset. This guide walks through adding Microsoft’s official repository, installing PowerShell, and running your first commands, with troubleshooting steps for common issues.
These steps support Debian 12 (Bookworm) and Debian 11 (Bullseye) on x86_64 (amd64) systems. Microsoft does not provide PowerShell packages for ARM processors via this repository. Debian 13 (Trixie) is not yet supported. Check Microsoft’s official PowerShell for Debian documentation for updates.
Add the Microsoft PowerShell Repository on Debian
Update Debian Before PowerShell Installation
Refresh your package index and upgrade existing packages before adding new repositories. This ensures your system has current package metadata and avoids dependency conflicts during installation:
If your user cannot run
sudocommands, follow the Debian sudoers guide first.
sudo apt update && sudo apt upgrade
Install Required Packages
Install the packages needed to download the GPG key over HTTPS and detect your Debian version. Minimal Debian installations and Docker containers often omit lsb-release, so installing it explicitly prevents errors later:
sudo apt install ca-certificates curl gpg lsb-release -y
These packages provide SSL certificate validation (ca-certificates), file downloading (curl), GPG key conversion (gpg), and release detection (lsb-release) needed to securely add external repositories. For more on download flags, see the curl command guide.
Add the Signing Key and Repository
Import the GPG Key
Import Microsoft’s signing key so APT can verify that packages from the repository are authentic and unmodified:
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-powershell.gpg
The -fsSL flags tell curl to fail silently on errors (-f), show no progress meter (-s), still display errors when they occur (-S), and follow redirects (-L). The gpg --dearmor command converts the ASCII-armored key to the binary format stored in /usr/share/keyrings/.
Add the PowerShell APT Repository
Create the repository configuration using the modern DEB822 .sources format. This format is more readable than the legacy one-line format and makes the signed-by relationship explicit:
cat <<EOF | sudo tee /etc/apt/sources.list.d/microsoft-powershell.sources
Types: deb
URIs: https://packages.microsoft.com/debian/$(lsb_release -sr)/prod
Suites: $(lsb_release -sc)
Components: main
Architectures: amd64
Signed-By: /usr/share/keyrings/microsoft-powershell.gpg
EOF
The $(lsb_release -sr) command inserts your Debian version number (11 or 12), while $(lsb_release -sc) inserts the codename (bullseye or bookworm). This makes the same command work on either supported release without manual editing.
Refresh the Package Index and Verify the Repository
Refresh APT so it reads the new repository, then confirm PowerShell is available before installing:
sudo apt update
apt-cache policy powershell
powershell:
Installed: (none)
Candidate: 7.5.4-1.deb
Version table:
7.5.4-1.deb 500
500 https://packages.microsoft.com/debian/12/prod bookworm/main amd64 Packages
Your output will show your Debian release codename and the current PowerShell version available. The version number changes with new releases.
Install PowerShell on Debian
Install PowerShell via APT
With the repository configured, install PowerShell using APT:
sudo apt install powershell
APT resolves and installs the required dependencies automatically, primarily libicu for internationalization support.
Alternative Packages: LTS and Preview
Microsoft publishes three PowerShell packages in the Debian repository:
- powershell (installed above): The latest stable release with new features and fixes.
- powershell-lts: Long-term support release with extended maintenance. Use this for production servers where stability matters more than new features.
- powershell-preview: Early access to upcoming releases. Useful for testing new features before they reach stable.
To install the LTS or preview version instead:
sudo apt install powershell-lts
sudo apt install powershell-preview
All three packages install the pwsh binary, so you can only have one installed at a time. Choose the package that matches your stability requirements.
Verify the Installation
Confirm PowerShell installed correctly by checking the version from your regular shell:
pwsh --version
PowerShell 7.5.4
Seeing a version number confirms that the pwsh binary is in your PATH and the installation completed successfully.
Start PowerShell on Debian
Launch an interactive PowerShell session by running:
pwsh
Your prompt changes to PS /home/username>, indicating you are now in PowerShell. All PowerShell cmdlets and syntax are available from this prompt. Type exit when you are done to return to your regular shell.
If you plan to use PowerShell remoting over SSH to manage remote Linux or Windows machines, enable OpenSSH first by following this Debian SSH guide.
PowerShell Command Examples on Debian
PowerShell cmdlets work the same on Linux as on Windows. Linux lacks some Windows-specific cmdlets (like those for Active Directory or Windows services), but the core language and most cross-platform cmdlets work identically. The following examples demonstrate common tasks.
Find Commands by Name
Search for available cmdlets using wildcard patterns. This example finds all cmdlets containing “service” in the name:
Get-Command -Name *service*
Read Help for a Cmdlet
View detailed help including syntax, parameters, and examples for any cmdlet:
Get-Help Get-Process -Full
The -Full parameter displays complete documentation. On first run, PowerShell may prompt you to update help files from the internet.
List Files and Directories
PowerShell uses Get-ChildItem to list directory contents, which is aliased to ls and dir for convenience:
Get-ChildItem /etc
Search Text in a File
Read a file and filter lines containing specific text using Select-String, which works like grep:
Get-Content /etc/os-release | Select-String PRETTY_NAME
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
View Running Processes
List running processes and sort them by CPU usage, displaying only the top 10:
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
Show Command History
Review commands you ran in the current PowerShell session:
Get-History
PowerShell also saves persistent history across sessions in ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt.
Troubleshooting PowerShell on Debian
lsb_release: command not found
When running the repository commands, you may see:
bash: line 1: lsb_release: command not found
This happens on minimal Debian installs, Docker containers, and cloud images that do not include lsb-release by default. Check whether it is installed:
dpkg -l lsb-release
dpkg-query: no packages found matching lsb-release
Install the package and verify the command works:
sudo apt install lsb-release -y
lsb_release -sr
12
The output shows your Debian major version number: 11 for Bullseye or 12 for Bookworm.
NO_PUBKEY or GPG Signature Errors
If apt update fails with a missing key error, the output looks like this:
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF E: The repository 'https://packages.microsoft.com/debian/12/prod bookworm InRelease' is not signed.
This means the GPG keyring file is missing or was not created correctly. Confirm the file exists:
ls -la /usr/share/keyrings/microsoft-powershell.gpg
If the file is missing, re-import the key:
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-powershell.gpg
Refresh APT to verify the repository now validates correctly:
sudo apt update
Unable to Locate Package powershell
If you attempt to install without configuring the repository first, APT cannot find the package:
E: Unable to locate package powershell
Confirm the repository configuration file exists and contains valid content:
cat /etc/apt/sources.list.d/microsoft-powershell.sources
If the file is missing or empty, create it using the repository setup commands in the installation section above, then run sudo apt update before attempting installation again.
Manage PowerShell on Debian
Update PowerShell on Debian
Update PowerShell to the latest version without upgrading every package on the system:
sudo apt update && sudo apt install --only-upgrade powershell
If you installed powershell-lts or powershell-preview, replace the package name in the command above. The --only-upgrade flag tells APT to upgrade the package only if it is already installed. For a full system upgrade that includes PowerShell, use sudo apt upgrade instead.
Remove PowerShell from Debian
Remove the PowerShell package and any dependencies that were automatically installed with it. Replace powershell with powershell-lts or powershell-preview if you installed one of those instead:
sudo apt remove powershell
sudo apt autoremove
Remove the repository configuration and GPG key so APT no longer checks for updates from Microsoft:
sudo rm /etc/apt/sources.list.d/microsoft-powershell.sources
sudo rm /usr/share/keyrings/microsoft-powershell.gpg
Refresh APT to confirm the repository is no longer active:
sudo apt update
Verify PowerShell is no longer available from any configured repositories:
apt-cache policy powershell
powershell: Installed: (none) Candidate: (none) Version table:
An empty version table confirms no repository provides the PowerShell package.
The following command permanently deletes PowerShell user data including command history, module caches, and any custom profiles. Only run it if you no longer need this data.
rm -rf ~/.config/powershell ~/.local/share/powershell
Conclusion
PowerShell is ready to use on your Debian system, with the Microsoft repository configured for future updates. The cmdlet examples above cover everyday tasks like searching files, viewing processes, and exploring available commands, but the real value comes from PowerShell’s object-oriented pipeline. Results from one command flow as structured objects into the next, making it straightforward to filter, sort, and transform data without parsing text output. When you need to manage both Linux and Windows machines or integrate with Azure and Microsoft 365 APIs, PowerShell provides a consistent scripting environment across platforms.