PowerShell 7 for Linux (Ubuntu), macOS and Windows

PowerShell is a scripting language and an alternative to the command-line interface (CLI). PowerShell is an automation tool consisting of (at least) three parts:

  • A shell, like the Command Prompt in Windows or the Terminal in Linux or macOS

  • A scripting language

  • A configuration management frameworks called Desired State Configuration (DSC)

Installing PowerShell 7

Installing PowerShell 7 on Ubuntu

  1. In the first line, we are updating the local pachkages with the latest versions from the default repositories.

> sudo apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
...
Reading package lists...Done
  1. In the second line, we’re installing some prerequisite packages:

> sudo apt-get install -y wget apt-transport-https software-properties-common
Reading package lists...Done
Building dependency tree...Done
wget is already the newest version (1.21.4-1ubuntu4.1)
...
  1. In the third line, we are grabbing the exact version of the operating system and then using that in the fourth line:

> source /etc/os-release
  1. Next, we use wget to download the correct repository for our operating system. This is the Linux package repository for Microsoft product (packages.microsoft.com)

> wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
  1. We’re registering packages.microsoft.com with dpkg, the Ubuntu package management system:

> sudo dpkg -i packages-microsoft-prod.deb
Setting up packages-microsoft-prod (1.1-ubuntu24.04) ...
  1. We’re deleting the key for security:

> rm packages-microsoft-prod.deb
  1. We’re updating again to make sure we’got tyhe latest list of packages for the new repository:

> sudo apt-get update
Get:1 https://packages.microsoft.com/ubuntu/24/04/prod noble InRelease [3600 B]
...
  1. Finally, we’re installing PowerShell:

> sudo apt-get install -y powershell

To start PowerShell:

> pwsh
PowerShell 7.5.1
PS /root >
PS /root > $PSVersionTable

Name                        Value
----                        -----
PSVersion                   7.5.1
PSEdition                   Core
GitCommitId                 7.5.1
OS                          Ubuntu 24.04.1 LTS
Platform                    Unix
PSCompatibleVersions        {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion   2.3
SerializationVersion        1.1.0.1
WSManStackVersion           3.0

dpkg: error processing package libc-bin ( - - configure)

If it is in WSL, try this:

> sudo mv /var/lib/dpkg/info/libc-bin.*/tmp/

> sudo dpkg –remove –force-remove-reinstreg libc-bin

> sudo dpkg –purge libc-bin

> sudo apt install libc-bin

> sudo mv /tmp/libc-bin.* /var/lib/dpkg/info/

or do this:

> sudo apt-get –reinstall install libc-bin

Installing PowerShell 7 on macOS

Installing PowerShell 7 on Windows