Install AZ CLI on Linux

Azure CLI (Command Line Interface) is a set of commands used to manage Azure resources directly from the command line. It provides a cross-platform command-line tool that allows users to perform tasks such as creating, managing, and deleting Azure resources from Windows, macOS, and Linux.

Ubuntu

Tested on Ubuntu 20.04 (Focal Fossa)

Requirements

  • Internet accessSUDO permissions
  • Process

Update Package Repository and upgrade packages First, update your package repository to ensure you have access to the latest packages then upgrade all installed packages to the current release.

sudo apt-get update && sudo apt-get upgrade

Remove a pre-installed Az CLI installation Ubuntu 20.04 (Focal Fossa) and 20.10 (Groovy Gorilla) include an azure-cli package with version 2.0.81 provided by the universe repository. This package is outdated and not recommended. If this package is installed, remove the package before continuing by running the command:

sudo apt remove azure-cli -y && sudo apt autoremove -y

Install AZ CLI using the Microsoft maintained script The easiest way to install the Azure CLI is through a script maintained by the Azure CLI team. This script runs all installation commands in one step. This script is downloaded via curl and piped directly to bash to install the CLI.

If you wish to inspect the contents of the script yourself before executing, download the script first using curl and inspect it in your favorite text editor.

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

Verify Installation After installation, you can verify that Azure CLI is installed correctly by checking its version:

az --version

Login to Azure Log in to your Azure account using the CLI. This will provide you with a code and a URL to visit on another device:

az login

When you run az login, you’ll receive a code and a URL (like https://microsoft.com/devicelogin).On a device with a web browser (like your personal computer or smartphone), go to the provided URL and enter the code.Once you authenticate successfully on that device, your Azure CLI session on the server will be logged in.

Error with GPG key at APT Warnings during the apt-get update process indicate a permissions issue with the GPG keyring file used by APT (Advanced Package Tool) for verifying the authenticity of packages from repositories. Specifically, the file /etc/apt/trusted.gpg.d/microsoft.gpg is not readable by the user _apt.

To resolve this issue, you need to adjust the permissions of the microsoft.gpg file so that it is readable by the _apt user. This can typically be done by changing the file’s permissions to allow global read access. Here’s how you can do it:

sudo chmod a+r /etc/apt/trusted.gpg.d/microsoft.gpg

References

https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt

Last modified July 21, 2024: update (e2ae86c)