Thursday, September 5, 2024

A Simple Guide to Checking, Installing, and Verifying Azure CLI on Ubuntu

Before diving into the installation process, it's a good idea to first check if the Azure CLI is already installed on your machine. This can save you time and avoid unnecessary installations.

Step 1: Check if Azure CLI is Already Installed

To check if Azure CLI is installed, simply run the following command to check the version:

az --version

If the command returns the version of Azure CLI, you're all set! This means Azure CLI is already installed, and there's no need to reinstall it. However, if you see the message az: command not found, it means Azure CLI isn't installed yet, and you'll need to proceed with the installation.

Step 2: Update Your Package Lists

If Azure CLI isn't installed, let's start by updating your system’s package lists:

sudo apt-get update

Step 3: Install the Necessary Prerequisites

To ensure a smooth installation, we'll need to install a few supporting packages:

sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg

Step 4: Add the Microsoft GPG Key

Next, we need to download and add the Microsoft GPG public key. This key is essential for verifying the packages we'll install:

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

Step 5: Add the Azure CLI Repository

Now, let’s add the official Azure CLI repository to your sources list:

AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list


Step 6: Install the Azure CLI

With the repository in place, you can now install Azure CLI by running the following commands:

sudo apt-get update
sudo apt-get install azure-cli


Step 7: Verify the Installation

Finally, to ensure the installation was successful, verify the version of Azure CLI installed on your system:

az --version

This command should display the installed version of the Azure CLI along with other helpful details.

No comments: