Azure CLI Installation on Ubuntu 24.04 LTS Guide

Author

Reads 1.1K

A spacious harbor terminal with large reflective windows overlooking the sea.
Credit: pexels.com, A spacious harbor terminal with large reflective windows overlooking the sea.

To install Azure CLI on Ubuntu 24.04 LTS, you'll first need to update the package index using the command `sudo apt update`. This step ensures that your system has the latest information about available packages.

Azure CLI can be installed on Ubuntu 24.04 LTS using the `apt` package manager. You can do this by running the command `sudo apt install azure-cli`.

The installation process may prompt you to accept the Microsoft repository GPG key. Accepting this key is necessary for the installation to proceed.

After installing the Azure CLI, you can verify the installation by running the command `az --version`. This will display the version of the Azure CLI you've just installed.

Prerequisites

To install Azure CLI on Ubuntu, you need to meet some prerequisites first.

First and foremost, you need to have a Python interpreter on your system to run Azure CLI commands.

Azure CLI is written in Python, so it requires a Python environment to execute commands.

Credit: youtube.com, How to Install Azure CLI (AZ) on Ubuntu 24.04 | Step-by-Step Guide

To get started, you can download the latest Python executable from the official Python website and install it on your Ubuntu machine.

Make sure to add Python to PATH while installing the application, as it's crucial for Azure CLI to work properly.

Here's a step to verify if Python is installed correctly: run az --version in the terminal to check if the module's installation is successful.

Installation

To install Azure CLI on Ubuntu, you can use the installation script maintained by the Microsoft Azure CLI team. This script runs all installation commands in one step, making the process easier.

You can download the script using the curl command and pipe the output to your bash shell to initialize the installation. Ensure you inspect the script for any malicious content before running it on your system.

Alternatively, you can use the apt package manager to install Azure CLI on Ubuntu and Debian OS. This involves adding Microsoft’s package source as a trusted repository and then using the apt package manager to pull the package on the system.

Credit: youtube.com, Install Azure CLI on an Ubuntu or Debian based system

Here are the necessary commands to install Azure CLI using the apt package manager:

  • Update the system packages with `sudo apt update`
  • Install the necessary packages with `sudo apt install curl lsb-release ca-certificates apt-transport-https gnupg`
  • Add the Microsoft package manager signing keys with `curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg` and `sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/`
  • Update the apt package sources and install the CLI tool with `sudo add-apt-repository https://packages.microsoft.com/repos/azure-cli` and `sudo apt update` followed by `sudo apt install azure-cli`

Ubuntu 24.04 LTS

Installing Azure CLI on Ubuntu 24.04 LTS Jammy Jellyfish is a straightforward process that involves updating the system packages, installing necessary packages, and adding the Microsoft package manager signing keys.

First, update the system packages by running the command "sudo apt update" in the terminal. This ensures you have the latest versions of all packages and their dependencies.

Next, install the necessary packages with the command "sudo apt install -y curl lsb-release ca-certificates apt-transport-https gnupg" to prepare for the Azure CLI installation.

To add the Microsoft package manager signing keys, run the command "curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg" to download and install the key.

Now, add the Azure CLI software repository with the command "sudo add-apt-repository https://packages.microsoft.com/repos/azure-cli" to access the package files for Azure CLI.

Finally, install Azure CLI using the command "sudo apt-get install azure-cli" to download and install the CLI tool.

Once installed, validate the installation by running the command "az --version" in the terminal to display the version of Azure CLI installed on your system.

For your interest: Upgrade Azure Cli

Installing

Lines of Code
Credit: pexels.com, Lines of Code

Installing Azure CLI on your Linux system can be a straightforward process. You can use the installation script maintained by the Microsoft Azure CLI team, which makes the installation easier.

One option is to use the one-liner command to install the Azure CLI. If you prefer this method, run the following command in the terminal: `curl https://aka.ms/install-azure-cli | bash`

To install the Azure CLI using the apt package manager, you'll need to update your system packages first. Run the command `sudo apt update` to ensure you have the latest versions of all packages and their dependencies.

You'll also need to install the necessary packages, including curl, lsb-release, ca-certificates, apt-transport-https, and gnupg. Run the command `sudo apt install -y curl lsb-release ca-certificates apt-transport-https gnupg` to pull the necessary packages on the system.

For Ubuntu 24.04 LTS Jammy Jellyfish, you can update the system packages by running the command `sudo apt update` and then install the necessary packages with `sudo apt install -y curl lsb-release ca-certificates apt-transport-https gnupg`.

Interior of old Grand Central Terminal building with arched windows and ornamental ceiling over classic balconies
Credit: pexels.com, Interior of old Grand Central Terminal building with arched windows and ornamental ceiling over classic balconies

To add the Microsoft package manager signing keys to the system trusted root, run the command `sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4D9F5CC301DE33A842E7FE969C5A9BB5D16FDECE`. Finally, update the apt package sources and install the CLI tool with `sudo apt update && sudo apt install -y azure-cli`.

Here are the steps to install Azure CLI on Ubuntu and Debian OS using the apt package manager:

  • Launch the Terminal on your ubuntu system and run the following command to perform the package updates:
  • Azure CLI requires some packages as a prerequisite, including curl, lsb-release, ca-certificates, apt-transport-https, and gnupg. Run the following command to pull the necessary packages on the system to prepare for install using the following commands:
  • The next step involves adding the Microsoft package manager signing keys to the system trusted root:
  • Finally, run the following command to update the apt package sources and install the CLI tool:

You can also use the following one command to install or update Azure CLI: `curl https://aka.ms/install-azure-cli | bash`. This script installs Python 3.8 under /usr/local/azcli and makes Azure CLI use it by setting an alias of az to PATH=/usr/local/azcli/bin:$PATH az.

Troubleshooting

If you're using Ubuntu 20.04 (Focal) or WSL and encounter a "no module named" issue, check if you installed the outdated azure-cli 2.0.81 from the focal/universe repository.

Remove the outdated package by running the command `sudo apt remove azure-cli -y && sudo apt autoremove -y`. This will resolve the issue.

Credit: youtube.com, Installing Azure Cli on Linux Using Bash

If you're still having trouble running the az command, try clearing your shell's command hash cache. This might resolve the problem. Make sure to restart your shell after installation to ensure the az command is recognized. The location of the az command is in the path specified by the installation instructions.

No Module Issue

If you're using Ubuntu 20.04 (Focal) or WSL and encounter issues with no module named 'decorator' or 'antlr4', it's likely due to an outdated azure-cli package.

The package you installed is probably the outdated azure-cli 2.0.81 from the focal/universe repository.

To resolve this, run the command sudo apt remove azure-cli -y && sudo apt autoremove -y to remove the outdated package.

Then, follow the instructions to install the latest azure-cli package.

Command Not Found

If you can't run the az command after installation, try clearing your shell's command hash cache to see if the problem is resolved.

This issue can occur if you didn't restart your shell after installation, so make sure to restart it to see if that fixes the problem.

The location of the az command needs to be in your $PATH, so double-check that it's there.

If you've checked all of the above and the problem persists, it's likely due to the command not being found, which can happen if the installation didn't complete correctly.

Usage

Credit: youtube.com, How to Install Azure CLI in Ubuntu 21.04 | Part - 01

To use Azure CLI on Ubuntu, you'll need to run the az interactive command to start using it interactively. This will install the interactive shell automatically.

You can also run Azure CLI as a Docker container if you prefer. First, install Docker on your Ubuntu system if you haven't already. Then, verify the Docker installation by running a command in your terminal.

Once Docker is set up, you can use the Azure CLI Docker image provided by Microsoft to run an isolated container or create a custom image. To do this, run the Docker command to install the CLI using docker run.

Recommended read: Docker Azure Cli Container

Using Interactively

If you want to run Azure CLI commands in a more efficient way, you can use the interactive shell. This is a great option if you're working on a complex task or want to try out multiple commands quickly.

Azure CLI will automatically install the interactive shell the first time you run the az interactive command. This means you don't need to do anything extra to get started.

A fresh viewpoint: Azure Cli Commands List

Credit: youtube.com, Building Interactive Applications with Explore

To start using Azure CLI interactively, issue the az interactive command. This will give you a command prompt where you can enter commands directly.

You can use the interactive shell to connect to Azure and manage your cloud environment. It's a convenient way to get things done without having to write a bunch of code.

If you don't already have the interactive shell installed, you can get it by running the az interactive command. This will install it for you automatically.

Here are some key things to keep in mind when using Azure CLI interactively:

  • Issue the az interactive command to start using the interactive shell.
  • Use the interactive shell to connect to Azure and manage your cloud environment.

Logging in

To log in to Azure, you must first create an account if you don't already have one. You can do this from the Azure portal by creating a free trial account.

If you're using a non-graphical user interface, you'll be given a token to log in on a browser from another device.

To log in, use the Azure CLI command, which will redirect you to your default browser where you'll need to provide your account credentials.

Once you've logged in, you'll be taken back to the terminal window, where Azure CLI will give you a brief overview of the subscriptions tied to your Azure account in JSON format.

Why Use?

A Close-Up Shot of a Person in a Black Hoodie Holding Boxes while Using a Terminal
Credit: pexels.com, A Close-Up Shot of a Person in a Black Hoodie Holding Boxes while Using a Terminal

Using Azure CLI can be a game-changer for your cloud management needs. You can install it on macOS, Windows, and Linux, making it a versatile tool for any environment.

Azure CLI is a cross-platform command-line tool that allows you to automate tasks with ease. This means you can run interactive commands in your terminal or use scripts to streamline your workflow.

One of the main advantages of Azure CLI is its ability to automate the provisioning and decommission of resources. This saves you time and effort, and reduces the risk of human error.

Azure CLI also helps with DevOps operations, making it a valuable tool for teams that need to manage their cloud infrastructure. By using Azure CLI, you can ease the management of your cloud infrastructure and focus on more important tasks.

Here are some of the key benefits of using Azure CLI:

  • Easily automate the provisioning and decommission of resources.
  • Helps you with your DevOps operations.
  • Ease the management of your cloud infrastructure.

Output Format Change

You can change the output format of Azure CLI to suit your needs. By default, Azure CLI will format your output in JSON format, which can take up a lot of terminal space.

Interior view of a modern terminal featuring escalators and large windows with people traveling.
Credit: pexels.com, Interior view of a modern terminal featuring escalators and large windows with people traveling.

To change the output format to a more readable table format, you can use the -o table option in your commands. For example, you can use this option with the az login command to get a more organized output.

The table output format is a great way to view your data in a clear and concise manner. You can try running the az login command again with the -o table option to see the difference for yourself.

Getting Command-Line Help

Getting Command-Line Help is a powerful feature of Azure CLI that allows you to learn more about the commands you can use.

You can list all available Azure CLI commands by running the command, which will present you with a list of all base commands.

To get more information about a specific command, you can use it to learn more about the command you're interested in. For example, to find out more about the vm command.

The output will show you commands that you can execute on a virtual machine, such as starting and stopping a VM or listing VMs.

You can even go further by getting more help on a particular action, like stopping a VM.

Frequently Asked Questions

How to install a specific version of Azure CLI?

To install a specific version of Azure CLI, use the command `sudo zypper install --from azure-cli azure-cli=-1.el7>`. This command allows you to specify the exact version you want to install.

Margarita Champlin

Writer

Margarita Champlin is a seasoned writer with a passion for crafting informative and engaging content. With a keen eye for detail and a knack for simplifying complex topics, she has established herself as a go-to expert in the field of technology. Her writing has been featured in various publications, covering a range of topics, including Azure Monitoring.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.