Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

PowerShell on Linux: Install & Use Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Open a terminal on your Linux machine. You can usually find it in your applications menu or by pressing Ctrl+Alt+T.
  2. Update your package lists (for Debian/Ubuntu) with sudo apt update. For CentOS/RHEL, use sudo yum update or sudo dnf update depending on your version.
  3. 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"
      (Replace focal with your Ubuntu codename if different, e.g., jammy for 22.04.) Then run sudo apt update and sudo 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, replace rhel/7 with rhel/8 or rhel/9.
  4. Start PowerShell by typing pwsh in the terminal. You'll see a prompt that looks like PS /home/yourname>.
  5. Verify the installation by running $PSVersionTable and checking the PSVersion property. It should show a version number like 7.4.x.
  6. Run your first command: type Get-Process to list running processes, or Get-Service (if you have systemd) to list services. PowerShell commands are called cmdlets, and they follow a Verb-Noun pattern.
  7. Create a script file: use any text editor (like nano or vim) to create a file with a .ps1 extension, for example myscript.ps1. Write a simple line like Write-Host "Hello from PowerShell", save it, then run it with ./myscript.ps1 from the PowerShell prompt.
  8. Connect to Microsoft services (optional): if you use Azure, install the Az module with Install-Module -Name Az -Scope CurrentUser -Force, then sign in with Connect-AzAccount. For Microsoft 365, install the Exchange Online module with Install-Module -Name ExchangeOnlineManagement and connect with Connect-ExchangeOnline.
  9. Exit PowerShell by typing exit or 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 update after adding the repository – you'll get a package not found error.
  • Typing powershell instead of pwsh – the binary is named pwsh on 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: ls works, cat works, but they map to PowerShell cmdlets.
  • Use the help system – type Get-Help Get-Process to 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 ~/powershell to 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 pwsh is not found after installation, check that the package installed correctly with dpkg -l powershell (Debian/Ubuntu) or rpm -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 Az or Update-Module -Name ExchangeOnlineManagement.
  • If you see a security error when running a script, check the execution policy with Get-ExecutionPolicy. If it's Restricted, set it to RemoteSigned as 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 -i or sudo 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.