Hey Linux enthusiasts! If you’re like me, you appreciate the power and flexibility that PowerShell brings to scripting and automation. Traditionally a Windows tool, PowerShell is now a cross-platform powerhouse, ready to enhance your Linux workflow.

Today, we’ll dive into the simplest way to get PowerShell up and running on your Linux system: using Snap.

Why Snap?

Snap is a universal package manager developed by Canonical (the folks behind Ubuntu). It simplifies software installation across various Linux distributions, offering self-contained packages called “snaps” that bundle an application and its dependencies.

For PowerShell, Snap offers a few key advantages:

  • Easy Installation: A single command does it all.
  • Automatic Updates: Snaps are automatically updated, keeping your PowerShell version fresh.
  • Cross-Distribution: Works seamlessly on Ubuntu, Debian, Fedora, and many other Linux flavors.

Let’s Get Started!

Step 1: Ensure Snap is Installed

Most modern Linux distros come with Snap pre-installed. To check, open your terminal and run:

snap version

If Snap isn’t already installed on your Ubuntu 24 server, you can install it by following these steps:

  1. Update the package list: sudo apt update
  2. Install Snap: sudo apt install snapd -y
  3. Ensure the snapd service is enabled and running:
    sudo systemctl enable --now snapd
    sudo systemctl start snapd
  4. Enable classic snap support by creating a symbolic link: sudo ln -s /var/lib/snapd/snap /snap

If you are using another distro, refer to your distro’s documentation for installation instructions.

Once Snap is installed, you can proceed to install PowerShell using the snap install command.

Step 2: Install PowerShell

This is the magic command:

sudo snap install powershell --classic

Let’s break it down:

  • sudo: Gives you the necessary administrative privileges for installation.
  • snap install: The command to install a snap package.
  • powershell: The name of the PowerShell snap.
  • –classic: Grants PowerShell full access to your system, similar to traditional packages.

Step 3: Verify and Launch

Once the installation finishes, verify you have PowerShell by checking its version:

pwsh --version

You should see the installed PowerShell version number. Now, launch PowerShell with:

pwsh

You’ll be greeted with the familiar PowerShell prompt, ready to unleash your scripting skills!

Starting and Exiting PowerShell

To start PowerShell, simply type pwsh in your terminal. When you’re done and need to exit PowerShell, type exit at the PowerShell prompt, and you’ll return to your standard Linux shell.

Basic PowerShell Usage Examples

Here are a few basic commands to get you started in PowerShell:

List Files and Directories:

Get-ChildItem

Create a New Directory:

New-Item -Name "ExampleDir" -ItemType Directory

Create a New File:

New-Item -Name "ExampleFile.txt" -ItemType File

Read File Content:

Get-Content "ExampleFile.txt"

Copy Files:

Copy-Item "source.txt" -Destination "destination.txt"

Advanced Tip: Preview Releases

If you’re adventurous and want to test out the latest PowerShell features before they’re officially released, you can install the preview version with:

sudo snap install powershell-preview --classic

Troubleshooting

If you encounter issues, here are a few tips:

  • Check Permissions: Ensure you’re using sudo for installation.
  • Snapd Service: Make sure the snapd service is running.
  • Network Connectivity: Verify your internet connection for downloading the snap.

Get Scripting!

That’s it! You’ve successfully installed PowerShell on your Linux system using Snap. Now you’re equipped to automate tasks, manage systems, and explore the vast PowerShell ecosystem. Harness the power of PowerShell to streamline your workflow and make your Linux experience even more powerful.