PowerShell on Linux: Install & Use Guide
In this article
Yes, you can install and use Microsoft's PowerShell on Linux, and it's worth doing if you work with Azure, Exchange Online, or any Microsoft cloud service, because the same commands you use on Windows work on Linux. This guide walks you through installing PowerShell on Ubuntu, Debian, or CentOS/RHEL, then shows you the basics of running it, writing scripts, and connecting to Microsoft services. You'll need a Linux machine with an internet connection and sudo access.
What You'll Need
- A Linux distribution (Ubuntu 20.04+, Debian 10+, CentOS 7+, or RHEL 7+ are officially supported)
- An internet connection to download packages
- Sudo or root access to install software
- A terminal emulator (you'll use the command line)
Step-by-Step
- Open a terminal on your Linux machine. You can usually find it in your applications menu or by pressing Ctrl+Alt+T.
- Update your package lists (for Debian/Ubuntu) with
sudo apt update. For CentOS/RHEL, usesudo yum updateorsudo dnf updatedepending on your version. - Install PowerShell using the official method for your distro:
- Ubuntu/Debian: Download the .deb package from the Microsoft repository. First, add the Microsoft signing key and repository:
wget -q https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-focal-prod focal main"
(Replacefocalwith your Ubuntu codename if different, e.g.,jammyfor 22.04.) Then runsudo apt updateandsudo apt install -y powershell. - CentOS/RHEL: Register the Microsoft repository and install:
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm sudo yum install powershell -y
For RHEL 8/9, replacerhel/7withrhel/8orrhel/9.
- Ubuntu/Debian: Download the .deb package from the Microsoft repository. First, add the Microsoft signing key and repository:
- Start PowerShell by typing
pwshin the terminal. You'll see a prompt that looks likePS /home/yourname>. - Verify the installation by running
$PSVersionTableand checking thePSVersionproperty. It should show a version number like 7.4.x. - Run your first command: type
Get-Processto list running processes, orGet-Service(if you have systemd) to list services. PowerShell commands are called cmdlets, and they follow a Verb-Noun pattern. - Create a script file: use any text editor (like
nanoorvim) to create a file with a.ps1extension, for examplemyscript.ps1. Write a simple line likeWrite-Host "Hello from PowerShell", save it, then run it with./myscript.ps1from the PowerShell prompt. - Connect to Microsoft services (optional): if you use Azure, install the Az module with
Install-Module -Name Az -Scope CurrentUser -Force, then sign in withConnect-AzAccount. For Microsoft 365, install the Exchange Online module withInstall-Module -Name ExchangeOnlineManagementand connect withConnect-ExchangeOnline. - Exit PowerShell by typing
exitor pressing Ctrl+D.
Common Mistakes
- Using the wrong repository URL for your distro version. Always check the codename (e.g., focal, jammy) matches your Ubuntu release.
- Forgetting to run
sudo apt updateafter adding the repository – you'll get a package not found error. - Typing
powershellinstead ofpwsh– the binary is namedpwshon Linux. - Running scripts without execution policy – on Linux, PowerShell doesn't enforce the same execution policy as Windows, but if you see an error about running scripts, you may need to set
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser. - Assuming all Windows modules work – some Windows-specific modules (like ActiveDirectory) don't work on Linux without additional setup.
Tips
- Use tab completion – type part of a command and press Tab to auto-complete.
- Learn the aliases – PowerShell has aliases for common Unix commands:
lsworks,catworks, but they map to PowerShell cmdlets. - Use the help system – type
Get-Help Get-Processto see examples and parameters. - Make PowerShell your default shell – you can set it with
chsh -s /usr/bin/pwsh(but note it may not be in the list of allowed shells). - Store scripts in a dedicated folder like
~/powershellto keep things organized. - Use the PowerShell Integrated Scripting Environment (ISE)? Not on Linux – instead use Visual Studio Code with the PowerShell extension for editing and debugging.
Troubleshooting
- If
pwshis not found after installation, check that the package installed correctly withdpkg -l powershell(Debian/Ubuntu) orrpm -qa | grep powershell(CentOS/RHEL). If it's not there, reinstall. - If you get a dependency error during installation (like missing libicu), install the dependencies first:
sudo apt install libicu-dev(or the equivalent for your distro). - If PowerShell starts but crashes immediately, it's often a missing ICU library. On Ubuntu, run
sudo apt install libicu70(or the version your distro uses). - If you can't connect to Microsoft services, check your network connection and that you have the latest module:
Update-Module -Name AzorUpdate-Module -Name ExchangeOnlineManagement. - If you see a security error when running a script, check the execution policy with
Get-ExecutionPolicy. If it'sRestricted, set it toRemoteSignedas mentioned above. - If the repository add fails, try downloading the .deb or .rpm package directly from the Microsoft packages site and install with
sudo dpkg -iorsudo rpm -i.
Frequently Asked Questions
Is PowerShell on Linux the same as on Windows?
Mostly yes – the core cmdlets and scripting language are identical. Some Windows-specific modules (like Active Directory) may not work without additional tools, but the command line experience is the same.
Can I run PowerShell scripts written for Windows on Linux?
Generally yes, if they don't rely on Windows-only features like the registry or specific COM objects. Many scripts work as-is.
Do I need to install .NET separately?
No, PowerShell includes its own .NET runtime. You don't need to install anything else.
Can I use PowerShell to manage my Linux system?
Yes, you can use PowerShell to manage files, processes, services, and even install software, but it's not a replacement for native Linux tools – it's more useful for cross-platform automation and Microsoft cloud management.
How do I update PowerShell?
Use the same package manager you installed it with: sudo apt update && sudo apt upgrade powershell for Debian/Ubuntu, or sudo yum update powershell for CentOS/RHEL.
Is PowerShell free to use on Linux?
Yes, PowerShell is open source and free to use on any platform.