Last active
July 3, 2025 00:09
-
-
Save joshooaj/31b2091d0000bd2dd8b4e01e2d82d8dd to your computer and use it in GitHub Desktop.
Install PowerShell on linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is a slightly modified version of the install script shared by | |
# by Mike F. Robbins on September 26th, 2024. | |
# Url: https://mikefrobbins.com/2024/09/26/how-to-install-powershell-7-and-essential-tools-on-linux/ | |
# Determine the system architecture | |
ARCH=$(dpkg --print-architecture) | |
# Downloads use x64 instead of amd64 now | |
if [ "$ARCH" = "amd64" ]; then | |
ARCH="x64" | |
fi | |
# Get the latest PowerShell version number | |
pwshVersion=$(curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep 'tag_name' | cut -d '"' -f 4 | sed 's/v//') | |
# Download PowerShell tarball for the detected architecture and version | |
downloadUrl="https://github.com/PowerShell/PowerShell/releases/download/v$pwshVersion/powershell-$pwshVersion-linux-$ARCH.tar.gz" | |
curl -L -o /tmp/powershell.tar.gz "$downloadUrl" | |
# Create the installation directory if it doesn't exist | |
sudo mkdir -p /opt/microsoft/powershell/7 | |
# Extract the tarball to the installation directory | |
sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7 | |
# Make pwsh executable | |
sudo chmod +x /opt/microsoft/powershell/7/pwsh | |
# Remove the existing symlink if one exists | |
sudo rm "/usr/bin/pwsh" | |
# Create a new symlink for pwsh | |
sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh | |
# Clean up by removing the downloaded tarball | |
rm /tmp/powershell.tar.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment