Alternate Ways to Install PowerShell on Linux
Alternate Ways to Install PowerShell on Linux
Microsoft’s PowerShell is a powerful cross-platform automation tool that can be installed on various Linux distributions. In addition to the standard installation methods, there are several alternate ways to get PowerShell up and running on your Linux system.
Snap Package
One of the easiest ways to install PowerShell on Linux is through the use of Snap packages. Snap is a container-based packaging format that makes it simple to install and maintain applications across a wide range of Linux distributions.
To get started, you’ll first need to ensure that snapd
is installed on your system. You can follow these instructions to set up snapd
if it’s not already present.
Once snapd
is installed, you can use the following commands to install the latest stable version of PowerShell:
# Install PowerShell
sudo snap install powershell --classic
# Start PowerShell
pwsh
If you prefer to use the latest long-term support (LTS) version, you can specify the --channel
parameter:
# Install PowerShell LTS
sudo snap install powershell --channel=lts/stable --classic
# Start PowerShell
pwsh
Snap will automatically keep your PowerShell installation up-to-date, but you can also manually trigger an upgrade using the sudo snap refresh
command.
Binary Archives
For more advanced deployment scenarios, PowerShell provides binary tar.gz
archives for various Linux platforms. This method allows you to install specific versions of PowerShell, including the latest stable, LTS, or preview releases.
To install PowerShell from a binary archive, follow these steps:
- Download the appropriate
tar.gz
file for your system architecture from the PowerShell releases page. - Create a target directory for the PowerShell installation, for example
/opt/microsoft/powershell/7
. - Extract the downloaded archive to the target directory using
sudo tar zxf powershell.tar.gz -C /opt/microsoft/powershell/7
. - Set the execute permissions on the
pwsh
binary withsudo chmod +x /opt/microsoft/powershell/7/pwsh
. - Create a symbolic link to the
pwsh
binary in your system’sPATH
, such assudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
.
Keep in mind that when using binary archives, you may need to install additional dependencies depending on your Linux distribution. The article provides a list of supported distributions and their corresponding dependency information.
.NET Global Tool
If you already have the .NET Core SDK installed on your system, you can easily install PowerShell as a .NET Global Tool:
dotnet tool install --global PowerShell
This will add the pwsh
command to your system’s PATH
, allowing you to start PowerShell from any terminal.
By exploring these alternate installation methods, you can choose the approach that best fits your Linux environment and deployment requirements. Whether you prefer the simplicity of Snap packages, the flexibility of binary archives, or the convenience of .NET Global Tools, PowerShell can be easily installed and utilized on a wide range of Linux distributions.
For more details and support, be sure to check the official PowerShell documentation.