How to install Azure CLI on Linux (AlmaLinux)

Reading Time: 7 minutes

The Microsoft Azure Command Line Interface (CLI) is an open source tool that allows users to manage and interact with Microsoft Azure services via the command line. It offers a flexible and powerful approach to scheduling deployments, automating tasks, and managing Azure resources. Its comprehensive command sets cover a wide range of Azure services, enabling users to automate tasks, implement Infrastructure as Code (IaC) practices, and integrate cloud management into DevOps workflows. Its cross-platform compatibility ensures flexibility across Windows, macOS, and Linux environments, and its support for extensions contributes to a comprehensive and adaptable cloud management ecosystem.

Azure CLI is compatible with AlmaLinux, a Red Hat Enterprise Linux (RHEL)-based distribution, and Debian. Installing Azure CLI on Linux (AlmaLinux) involves a few simple steps, including ensuring the installation of necessary dependencies and adding the Azure CLI repository. Users can seamlessly integrate Azure CLI with AlmaLinux by following a straightforward installation process documented here. This setup enables them to perform various management and automation tasks directly from the command line across Azure services.

Key points

After reading this article, you will have a keen understanding of how to perform the following tasks:

  • Installing Azure CLI on Linux (AlmaLinux).
  • Verifying the Azure CLI installation.
  • Logging into Azure.
  • Installing a specific version of the Azure CLI.
  • Updating Azure CLI.
  • Uninstalling Azure CL.
  • Getting starting with cloud hosting options from Liquid Web.

How to install Azure CLI on Linux (AlmaLinux)

Prerequisites

  • Operating system and version. AlmaLinux OS 8.
  • Access. Ensure you have root or sudo access to install the Azure CLI.

To install Azure CLI on Linux (AlmaLinux), follow the instructions in the subsequent sections.

Step #1. Update the AlmaLinux system

Before installing Azure CLI, you must update the AlmaLinux system to reflect the most recent changes. To do so, use the following command:

sudo dnf update

Step #2. Install dependencies

To install the necessary dependencies on the AlmaLinux system, use the following command:

sudo dnf install ca-certificates curl lsb gnupg

This command ensures that your AlmaLinux system will have:

Step #3. Install Azure CLI on AlmaLinux

Option 3.1. Installing the Azure CLI using the package manager

3.1.1. Download and install the Microsoft signing key

To ensure the authenticity of the Azure CLI packages, you need to download and install the Microsoft GnuPG signing key using the following commands:

curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/pki/rpm-gpg/microsoft.asc.gpg > /dev/null

3.1.2. Add the Azure CLI software repository

To add the Azure CLI software repository, use the following command:

echo -e "[azure-cli]
name=Azure CLI
baseurl=https://packages.microsoft.com/yumrepos/azure-cli
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc" | sudo tee /etc/yum.repos.d/azure-cli.repo

3.1.3. Update repository information and install the azure-cli package

To update repository information, use the following command:

sudo dnf check-update

To install Azure CLI on Linux (AlmaLinux), use the following command:

sudo dnf install azure-cli

Here is the output:

]# sudo dnf install azure-cli
Azure CLI                                                                                                            22 kB/s | 1.5 kB     00:00
Dependencies resolved.
====================================================================================================================================================
 Package                            Architecture                    Version                                Repository                          Size
====================================================================================================================================================
Installing:
 azure-cli                          x86_64                          2.38.1-1.el7                           azure-cli                           50 M

Transaction Summary
====================================================================================================================================================
Install  1 Package

Total download size: 50 M
Installed size: 709 M
Is this ok [y/N]: y
Downloading Packages:
azure-cli-2.38.1-1.el7.x86_64.rpm                                                                                    53 MB/s |  50 MB     00:00
----------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                53 MB/s |  50 MB     00:00
Azure CLI                                                                                                           8.7 kB/s | 983  B     00:00
Importing GPG key 0xBE1229CF:
 Userid     : "Microsoft (Release signing) <gpgsecurity@microsoft.com>"
 Fingerprint: BC52 8686 B50D 79E3 39D3 721C EB3E 94AD BE12 29CF
 From       : https://packages.microsoft.com/keys/microsoft.asc
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                            1/1
  Installing       : azure-cli-2.38.1-1.el7.x86_64                                                                                              1/1
  Running scriptlet: azure-cli-2.38.1-1.el7.x86_64                                                                                              1/1
  Verifying        : azure-cli-2.38.1-1.el7.x86_64                                                                                              1/1

Installed:
  azure-cli-2.38.1-1.el7.x86_64

Complete!

Option 3.2. Downloading and installing manually

3.2.1. Download and install the Azure CLI

To download and install the Azure CLI manually, use the following command:

curl -L https://aka.ms/InstallAzureCli | bash

Warning: Scripts should only be run from trusted sources to avoid security risks. Verify the source before executing commands directly from the internet.

Here is the output:

~]# curl -L https://aka.ms/InstallAzureCli | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  1405  100  1405    0     0   1525      0 --:--:-- --:--:-- --:--:--  1525
Downloading Azure CLI install script from https://azurecliprod.blob.core.windows.net/install.py to /tmp/azure_cli_install_tmp_u8jx4f.
######################################################################## 100.0%
/tmp/azure_cli_install_tmp_u8jx4f: OK
Running install script.
—-
—-
-- Installation successful.
-- Run the CLI with /root/bin/az --help

The/root/bin/az --helpcommand is requesting help documentation for the Azure CLI. It will likely output information about using the Azure CLI, including a list of commands, their options, and usage examples. This documentation can be useful for users who want to understand how to use the Azure CLI or need help with a specific command.

3.2.2. Add Azure CLI to PATH

Add the Azure CLI executable to your AlmaLinux system's PATH:

export PATH=$PATH:/usr/local/bin/az

Optionally, add this line to your shell profile file (for example., ~/.bashrc or ~/.zshrc) to make it permanent.

Step #4. Verify the Azure CLI installation

To verify that Azure CLI is installed, run the following command:

az version

Or:

 az --version 

Here is the output:

]# az version
{
  "azure-cli": "2.38.1",
  "azure-cli-core": "2.38.1",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

Or:

]# az --version
azure-cli                         2.38.1 *

core                              2.38.1 *
telemetry                          1.0.6 *

Step #5. Log into Azure

To log into your Azure account, use the following command:

az login

Here is the output:

]# az login
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code BKHCBR45P to authenticate.

The URL https://microsoft.com/devicelogin will be redirected to https://login.microsoftonline.com/common/oauth2/deviceauth where you will enter the code BKHCBR45P to authenticate in our example.

Here is the output:

How to install Azure CLI on Linux (AlmaLinux) — the URL https://microsoft.com/devicelogin will be redirected to https://login.microsoftonline.com/common/oauth2/deviceauth where you will enter the code BKHCBR45P to authenticate in our example.


Click the Next button and follow the instructions to complete the authentication process.

Installing a specific version of Azure CLI

Before installing a specific version of the Azure CLI, you may want to view all versions. Here the steps for doing that.

Step #1. View the available versions of Azure CLI

Use the following command to view the available versions:

 dnf list --showduplicates azure-cli

Here is the output:

]# dnf list --showduplicates azure-cli
Last metadata expiration check: 0:00:11 ago on Sat 27 Jan 2024 12:07:23 PM UTC.
Installed Packages
azure-cli.x86_64                                                       2.38.1-1.el7                                                       @azure-cli
Available Packages
azure-cli.x86_64                                                                                                      azure-cli
azure-cli.x86_64                                                       2.0.21-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.0.22-1.el7                                                       azure-cli
—-
—-
azure-cli.x86_64                                                       2.32.0-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.33.0-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.33.1-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.34.0-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.34.1-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.35.0-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.36.0-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.37.0-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.38.0-1.el7                                                       azure-cli
azure-cli.x86_64                                                       2.38.1-1.el7                                                       azure-cli

Step #2. Install a specific Azure CLI version

To install a specific Azure CLI version, use the following command:

sudo dnf install azure-cli-<version>-1.el7

Replace <version> in the command's syntax as per your requirement.

For example, to install Azure CLI 2.33.1 version, use the following command:

sudo dnf install azure-cli-2.33.1-1.el7

Here is the output:

]# sudo dnf install azure-cli-2.33.1-1.el7
Last metadata expiration check: 0:02:47 ago on Sat 27 Jan 2024 12:07:23 PM UTC.
Dependencies resolved.
====================================================================================================================================================
 Package                            Architecture                    Version                                Repository                          Size
====================================================================================================================================================
Downgrading:
 azure-cli                          x86_64                          2.33.1-1.el7                           azure-cli                           49 M

Transaction Summary
====================================================================================================================================================
Downgrade  1 Package

Total download size: 49 M
Is this ok [y/N]: y
Downloading Packages:
azure-cli-2.33.1-1.el7.x86_64.rpm                                                                                    22 MB/s |  49 MB     00:02
----------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                22 MB/s |  49 MB     00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                            1/1
  Downgrading      : azure-cli-2.33.1-1.el7.x86_64                                                                                              1/2
  Cleanup          : azure-cli-2.38.1-1.el7.x86_64                                                                                              2/2
  Running scriptlet: azure-cli-2.38.1-1.el7.x86_64                                                                                              2/2
  Verifying        : azure-cli-2.33.1-1.el7.x86_64                                                                                              1/2
  Verifying        : azure-cli-2.38.1-1.el7.x86_64                                                                                              2/2

Downgraded:
  azure-cli-2.33.1-1.el7.x86_64

Complete!

How to update Azure CLI

To update the Azure CLI on AlmaLinux, please follow these steps.

Step #1. Update Package Information

Ensure the information on available packages is accurate and current on your AlmaLinux system. Use the following command to update the package information:

sudo dnf check-update

Step #2. Update Azure CLI

Once the package information has been updated, update the Azure CLI using the following command:

sudo dnf upgrade azure-cli

How to uninstall Azure CLI on AlmaLinux

To uninstall Azure CLI on Linux (AlmaLinux), here are the steps.

Step #1. Remove the Azure CLI package from your AlmaLinux system

To remove the Azure CLI package from your AlmaLinux system, use the following command:

sudo dnf remove azure-cli

Here is the output:

]# sudo dnf remove azure-cli
Dependencies resolved.
====================================================================================================================================================
 Package                            Architecture                    Version                               Repository                           Size
====================================================================================================================================================
Removing:
 azure-cli                          x86_64                          2.38.1-1.el7                          @azure-cli                          709 M

Transaction Summary
====================================================================================================================================================
Remove  1 Package

Freed space: 709 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                            1/1
  Erasing          : azure-cli-2.38.1-1.el7.x86_64                                                                                              1/1
  Verifying        : azure-cli-2.38.1-1.el7.x86_64                                                                                              1/1

Removed:
  azure-cli-2.38.1-1.el7.x86_64

Complete!

Step #2. Remove the Azure CLI repository configuration file

If you don't plan to reinstall the Azure CLI, remove the Azure CLI repository information using the following command:

sudo rm /etc/yum.repos.d/azure-cli.repo

Step #3. Remove Microsoft signing key

Remove the Microsoft signing key using the following commands if you do not use any additional Microsoft packages:

MSFT_KEY=$(rpm -qa gpg-pubkey\* --qf "%{version}-%{release} %{summary}\n" | grep Microsoft | awk '{print $1}')

sudo rpm -e --allmatches gpg-pubkey-$MSFT_KEY

This command finds the GPG signing key used by Microsoft packages, including the Azure CLI. Then, it extracts the key version from the list of installed GPG keys, which is used to identify the Microsoft key uniquely. Finally, The rpm -e command then removes the identified GPG key.

Step #4. Remove data

If you do not plan to reinstall Azure CLI and want to clean up any residual data, use the following command:

rm -r ~/.azure

The command removes the Azure CLI configuration and data from the user's home directory, including settings, configurations, and cached data related to the Azure CLI.

Elevate your experience — optimize AlmaLinux with Azure CLI on our servers

Integrating Azure CLI into the AlmaLinux environment is an easy and necessary step for those seeking effective control of Microsoft Azure resources. This article's insightful explanations of the procedure make it simple for users to understand integration's foundations. Focused on simplicity and clarity, the steps above ensure a seamless installation and configuration process for beginner and experienced users alike.

Liquid Web offers a comprehensive and modern hosting solution that enhances your cloud experience. With professional advice, you can easily install Azure CLI on Linux (AlmaLinux) for seamless integration. Liquid Web provides individualized support, affordable pricing, and business-specific flexibility, making Liquid Web a top choice over Microsoft Azure. Regardless of your unique scenario, the Azure CLI is a great asset to leverage.

Our feature-rich Cloud Studio at Liquid Web, which works with AWS and Azure, further enhances the experience. With Liquid Web, you can find choice, innovation, and the latest technologies — making you stand out in the ever-changing cloud computing industry.

Avatar for Mohammed Noufal

About the Author: Mohammed Noufal

Mohammed Noufal is a B.Tech graduate with a decade of experience in server administration and web hosting. He is a father to two daughters and finds fulfillment in their growth. In his free time, he enjoys blogging, sharing experiences, and listening to music. With a strong technical background, family commitment, and creative outlets, he represents a well-rounded life journey.

Latest Articles

In-place CentOS 7 upgrades

Read Article

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article