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.

powershell

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:  CloudStrike Microsoft BSOD Workaround

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

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

Translate »