Practical Linux, Windows Server and cloud guides for IT pros.

How to Install and Use PowerShell on Ubuntu Linux

PowerShell, once exclusive to the Windows ecosystem, is now a cross-platform automation and configuration management framework. It allows you to use its object-oriented pipeline and powerful cmdlets on Linux systems, providing a bridge between Windows and Linux administration tasks.

Filed under

,

Published

Written by

Last updated

PowerShell one-liners for Windows Server administration

TL;DR

  • PowerShell 7 is cross-platform — same shell, same cmdlets, same scripts on Windows, Linux and macOS.
  • Ubuntu install: add Microsoft’s apt repo, then sudo apt install powershell.
  • Launch with pwsh; auto-complete and history work like bash.
  • Useful when scripting against AD, Exchange or Microsoft Graph from a Linux box.

What is running PowerShell on Ubuntu Linux?

PowerShell is Microsoft’s task automation and configuration management framework. PowerShell 7 (the current major) is built on .NET and runs cross-platform — the same shell environment, cmdlets, and scripts work the same on Windows, Linux and macOS, with platform-specific cmdlets (e.g. AD-related) loaded only where they apply.

Why install PowerShell on Linux? Three common reasons: scripting against Microsoft 365 / AD / Exchange from a Linux CI runner; using PowerShell-native cloud SDKs (Az, AWS.Tools); or mixed-platform teams who want to write one automation script that runs everywhere instead of two.

Prerequisites

  • Ubuntu 22.04, 24.04 or 26.04 LTS.
  • sudo access for the apt repo install.
  • Network access to Microsoft’s apt repo (packages.microsoft.com).

How to use this guide

The sections below walk through the practical commands and options. After the main content you’ll find a Verification block (sanity-check it actually worked), a Troubleshooting block (common error messages and what to do), and Related reading for follow-on topics.

PowerShell, once exclusive to the Windows ecosystem, is now a cross-platform automation and configuration management framework. It allows you to use its object-oriented pipeline and powerful cmdlets on Linux systems, providing a bridge between Windows and Linux administration tasks.

powershell

Quick Answer

  1. Download the Microsoft APT key and repository: curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
  2. Add the PowerShell repository and update: sudo apt update
  3. Install PowerShell: sudo apt install -y powershell
  4. Launch PowerShell: pwsh
  5. Verify version: $PSVersionTable.PSVersion

Why Use PowerShell on Linux?

The first thing you might ask is why should I bother using POSH on Linux? There are several reasons why you may consider PowerShell on Linux:

  1. Unified Toolset:
    Manage both Windows and Linux systems using the same scripting language and cmdlets. Traditionally, managing mixed environments (Linux and Windows) meant juggling disparate tools and skill sets. PowerShell on Linux bridges this gap, offering a unified approach that simplifies administration and reduces the learning curve for those familiar with PowerShell.
  2. Automation & Configuration Management:
    Leverage PowerShell’s capabilities for complex automation tasks and infrastructure configuration. Linux boasts a rich ecosystem of automation tools, but PowerShell brings its unique strengths to the table. Its object-oriented pipeline, powerful cmdlets, and integration with .NET provide new possibilities for sophisticated automation and configuration management tasks on Linux.
  3. .NET Integration:
    Seamlessly interact with the .NET ecosystem and leverage its libraries. While Linux has its share of frameworks, PowerShell’s seamless .NET integration opens the door to leveraging a vast collection of libraries and tools built on the .NET platform, further extending what’s achievable on Linux.
  4. Cross-Platform Compatibility:
    Write scripts that run consistently on Windows, Linux, and macOS. For those working across multiple platforms, PowerShell on Linux eliminates the need for platform-specific scripting. This consistency saves time, reduces errors, and promotes code reusability, whether you’re managing servers, deploying applications, or orchestrating complex tasks.

It’s about breaking down barriers and providing a more versatile and powerful toolkit for tackling the challenges of modern IT environments.

Technical Guide: Installing and Using PowerShell on Ubuntu

What do you need?

  • Ubuntu Linux: Ensure you have a supported Ubuntu version (e.g., 20.04 LTS or later).
  • Superuser Access: You’ll need sudo privileges to install packages and configure PowerShell.

Step 1 – Installation

Update the Package List that Keeps your system up-to-date with the latest package information. Install the dependencies that PowerShell relies on certain packages for its operation, then Import the Microsoft Repository Key to ensure the authenticity of packages from Microsoft’s repository.

Finally, Install PowerShell and Verify the Installation

sudo apt update -y
sudo apt install -y wget apt-transport-https software-properties-common
wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo apt install -y powershell
pwsh --version

Step 2 – Start Using PowerShell (POSH)

Alright, you’ve got PowerShell installed – now let’s put it to work!

To kick things off, launch an interactive PowerShell session right from your terminal. Just type pwsh and hit enter. You’ll see the familiar PowerShell prompt, ready for action.

While PowerShell is designed to be cross-platform, there are some inherent complexities when running it on Linux:

#1: Compatibility:

  • Cmdlets and Modules:
    Not all Windows-specific cmdlets and modules are available or function identically on Linux. This is because some cmdlets rely on underlying Windows technologies that don’t exist on Linux.
     
  • Paths and File Systems:
    Linux uses a different file system structure and path conventions than Windows (e.g., forward slashes vs. backslashes). Scripts may require adjustments to work correctly.  
  • Case Sensitivity:
    Linux is case-sensitive while Windows is not. This can lead to issues if scripts aren’t written with this in mind.

#2: Environment and Dependencies:

  • .NET Framework vs .NET Core:
    PowerShell on Linux relies on .NET Core, which while largely compatible, can have subtle differences from the full .NET Framework on Windows.
     
  • Missing Libraries:
    Certain functionalities might depend on libraries not present by default on Linux distributions. You might need to install them separately.

#3: System Administration Differences:

  • Service Management:
    Managing services on Linux is different from Windows. Cmdlets like Get-Service might not work as expected, and you might need to use Linux-native commands.
  • User and Permissions:
    Linux has a different user and permission model compared to Windows. This can affect script execution and access to resources.  

#4: Tooling and Integration:

  • IDE Support:
    While some IDEs offer PowerShell support on Linux, the experience might not be as feature-rich as on Windows.
  • Integration with Linux Tools:
    PowerShell might not seamlessly integrate with all Linux tools and utilities.

#5: Community and Support:

  • Smaller Community:
    The PowerShell community on Linux is smaller compared to Windows. Finding support and resources might be slightly harder.
  • Microsoft Support:
    While Microsoft supports PowerShell on Linux, the level of support might not be as extensive as for the Windows version.

It’s that simple, you are now ready to start using PowerShell on Linux.

Elsewhere On TurboGeek:  How to Install Nano Server on VMware – A Step-by-Step Guide

Verification

Sanity-check the change actually worked:

  • pwsh --version — confirms PowerShell is installed.
  • pwsh -c 'Get-PSDrive' — lists PSDrives, confirms the runtime works.
  • pwsh -c 'Install-Module -Name Microsoft.Graph -Scope CurrentUser' — confirms module install works.

Troubleshooting

pwsh: command not found — The package installed but isn’t on PATH. Try /snap/bin/pwsh if installed via snap, or /usr/bin/pwsh for apt; refresh the shell with hash -r.

apt repo signature error — Microsoft rotates signing keys. Re-add: curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/microsoft.gpg.

Module install fails behind a proxy — Set $env:HTTPS_PROXY in pwsh, or pass -Proxy to Install-Module.

Authoritative sources

References: Microsoft — Install PowerShell on Ubuntu, PowerShell releases on GitHub.

Related reading

Leave a Reply

Your email address will not be published. Required fields are marked *

Find more on the site

Keep reading by topic.

If this post was useful, the fastest way to keep going is to pick the topic you work in most often.

Want another useful post?

Browse the latest posts, or support TurboGeek if the site saves you time regularly.

Translate »