To install Azure PowerShell on Linux we first need install PowerShell Core (PowerShell 7 or later) and then install the Az module. The Az module provides the Azure-specific cmdlets

Below I will show this for SUSE Linux Enterprise (SLES 15).



Install .NET Core on SLES 15

First we need to install the Microsoft RPM repository package, so run the following command.

# rpm -Uvh https://packages.microsoft.com/config/sles/15/packages-microsoft-prod.rpm


Currently, the SLES 15 Microsoft repository setup package installs the microsoft-prod.repo file to the wrong directory, preventing zypper from finding the .NET packages. To fix this problem, create a symlink in the correct directory.

This seems to be resolved meanwhile!

Source: https://learn.microsoft.com/en-us/dotnet/core/install/linux-sles#sles-15

# ln -s /etc/yum.repos.d/microsoft-prod.repo /etc/zypp/repos.d/microsoft-prod.repo


To trust Microsoft’s GPG (GNU Privacy Guard) public key to verify the authenticity of the packages, run the following command:

This command imports Microsoft’s GPG signing key into your RPM-based Linux system (like RHEL, CentOS, or SUSE).

A GPG key is used to verify the integrity and authenticity of packages. When you install or update packages (like the Azure CLI or .NET SDK from Microsoft’s repositories), your system uses this key to ensure they haven’t been tampered with.

# rpm --import https://packages.microsoft.com/keys/microsoft.asc


Now we can install the .NET SDK.

The .NET SDK allows you to develop apps with .NET. If you install the .NET SDK, you don’t need to install the corresponding runtime. To install the .NET SDK, run the following command:

# zypper install dotnet-sdk-9.0


The ASP.NET Core Runtime will installed along with the .NET SDK, so it is already installed on our system. To install it separately we can run the following command.

The ASP.NET Core Runtime allows you to run apps that were made with .NET that didn’t provide the runtime. The following command installs the ASP.NET Core Runtime, which is the most compatible runtime for .NET. In your terminal, run the following command:

# zypper install aspnetcore-runtime-9.0


Install PowerShell (Core) on Linux

All packages are available on our GitHub releases page. After the package is installed, run pwsh from a terminal. Run pwsh-preview if you installed a preview release.

Use the following shell commands to download and install PowerShell (Core) from the tar.gz binary archive. Change the URL to match the version of PowerShell you want to install.

# Download the powershell '.tar.gz' archive
curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.5.1/powershell-7.5.1-linux-x64.tar.gz

# Create the target folder where powershell will be placed
sudo mkdir -p /opt/microsoft/powershell/7

# Expand powershell to the target folder
sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7

# Set execute permissions
sudo chmod +x /opt/microsoft/powershell/7/pwsh

# Create the symbolic link that points to pwsh
sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh


We can also create a new *.sh file and adding execution permissions to run all commands above at once.


To uninstall the binaries we can run.

# sudo rm -rf /usr/bin/pwsh /opt/microsoft/powershell


Source: https://learn.microsoft.com/en-us/powershell/scripting/install/install-other-linux?view=powershell-7.5#installation-using-a-binary-archive-file

Install the Az Module

Now as we have installed PowerShell Core successfully on Linux, we finally need to install the Az modules.

The Az PowerShell module is a set of cmdlets for managing Azure resources directly from PowerShell. PowerShell provides powerful features for automation that can be leveraged for managing your Azure resources, for example in the context of a CI/CD pipeline.

Source: https://learn.microsoft.com/en-us/powershell/azure/new-azureps-module-az


Open a new PowerShell session by enter pwsh and run the following cmdlet.

pwsh is the command used to start PowerShell, the cross-platform shell and scripting language from Microsoft. It’s the executable file name for PowerShell Core (versions 6 and later) on Windows, macOS, and Linux. You can use pwsh in a terminal or command prompt to launch a new PowerShell session

PS /> Install-Module -Name Az -Repository PSGallery -Force

Determine installed PowerShell Version

To determine the version of PowerShell Core (also known as PowerShell 7+), use the following command in your PowerShell terminal:

Links

Install the .NET SDK or the .NET Runtime on SLES
https://learn.microsoft.com/en-us/dotnet/core/install/linux-sles

Install PowerShell on Linux
https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux

Installing PowerShell on Red Hat Enterprise Linux (RHEL)
https://learn.microsoft.com/en-us/powershell/scripting/install/install-rhel?view=powershell-7.5