Installing and Configuring Azure CLI: A Step-by-Step Guide

Before you can manage Azure resources from the command line, you need the Azure CLI installed and authenticated. This page walks through installation on every major platform, the login process including the device code flow for headless environments, and the steps to go from a fresh install to running your first real command against Azure.

Before You Start

You need an Azure account with at least one subscription. If you do not have one yet, Microsoft offers a free account with credits for new users — see Azure Free Tier for what is included. You will also need a terminal: Command Prompt, PowerShell, Windows Terminal, or bash on macOS/Linux.

If you want to skip local installation entirely and use the CLI from a browser, Azure Cloud Shell provides a pre-configured environment with no install required. This page focuses on local installation for when you want the CLI available in your own environment.

Installing on Windows

Microsoft distributes an MSI installer for Windows that handles everything including adding the az command to your PATH.

  1. Go to the Azure CLI documentation page and download the latest MSI installer for Windows (x64). The direct download URL from Microsoft’s documentation is straightforward to find by searching “install azure cli windows”.
  2. Run the MSI. Accept the license agreement. Click through the installation wizard with default options. The installer adds Azure CLI to your PATH automatically.
  3. Open a new Command Prompt, PowerShell, or Windows Terminal window (not an existing one — it needs to pick up the updated PATH).
  4. Verify the install:
az --version

You should see output listing the CLI version number and versions of its Python dependencies. If you see “command not found” or “az is not recognized”, close all terminal windows and open a fresh one.

Alternative: Install via winget

If you have the Windows Package Manager (winget) available (built into Windows 11 and available for Windows 10), you can install from the command line:

winget install --exact --id Microsoft.AzureCLI

This installs the same CLI as the MSI and adds it to your PATH.

Windows Subsystem for Linux (WSL)

If you work primarily in WSL, install the CLI inside the WSL environment using the Linux instructions below rather than the Windows MSI. The two installations are independent — commands you run inside WSL use the WSL installation; commands in a native Windows terminal use the Windows installation.

Installing on macOS

The recommended method on macOS is Homebrew:

brew update && brew install azure-cli

If you do not have Homebrew, install it first from brew.sh. After the CLI installs, verify it:

az --version

To update the CLI later:

brew upgrade azure-cli

Homebrew puts the CLI binary in /usr/local/bin (Intel Macs) or /opt/homebrew/bin (Apple Silicon Macs). Both should be on your PATH automatically if Homebrew is set up correctly.

Note

On Apple Silicon (M1/M2/M3), there was historically a delay before Homebrew’s Azure CLI bottle supported the arm64 architecture natively. Today the CLI fully supports Apple Silicon and Homebrew handles the correct architecture automatically.

Installing on Linux

Ubuntu and Debian (apt)

Microsoft maintains an official apt repository for Azure CLI. The quickest way to install is:

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

This script adds the Microsoft signing key, adds the repository to your sources list, and installs the CLI in one step. After installation, verify:

az --version

To update later:

sudo apt-get update && sudo apt-get install --only-upgrade azure-cli

Red Hat, CentOS, Fedora (dnf/yum)

Import the Microsoft GPG key and add the repository:

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

# For Fedora / RHEL 8+
sudo dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
sudo dnf install azure-cli

Adjust the RHEL version in the URL to match your system (7, 8, or 9).

Any Linux: pip install

If your distribution is not listed or you want to install without root access:

pip install azure-cli

This works in virtual environments. The pip installation does not add shell completions automatically, but the CLI itself functions the same way.

Authenticating: az login

With the CLI installed, the next step is to authenticate your terminal session with your Azure account. There are two main login methods.

Interactive Browser Login

This is the standard method for local development machines:

az login

The CLI opens a browser window pointing to a Microsoft sign-in page. You sign in with the Microsoft account or work/school account that has access to your Azure subscription. After successful sign-in, the browser shows a confirmation message and the terminal displays a JSON list of your accessible subscriptions.

If the CLI cannot open a browser automatically (for example, the command is running inside a terminal multiplexer that cannot launch a GUI), you can pass the URL from the error message manually to a browser.

Device Code Login (Headless Environments)

When there is no browser available — a remote server, a Docker container, WSL without a display server, or CI/CD — use device code flow:

az login --use-device-code

The terminal prints output similar to:

To sign in, use a web browser to open the page https://microsoft.com/devicelogin
and enter the code ABCDE1234 to authenticate.

Open that URL on any device — your phone, a different computer, anything with a browser — enter the displayed code, and sign in. The terminal polls until authentication completes, then shows your subscriptions. This flow is useful for initial setup on servers where you can use a different device as the browser.

Tip

For production automated workloads (CI/CD pipelines, background scripts), do not use interactive login. Use a service principal with a client secret or certificate, or use a managed identity if the code runs inside Azure. The az login approaches above are for human operators. See Azure Service Principals for automated authentication.

Setting Your Subscription

After login, the CLI shows all subscriptions your account can access. If you have multiple subscriptions, you need to tell the CLI which one to use. Skipping this step is the most common source of confusion for new users.

First, list your subscriptions:

az account list --output table

The output shows each subscription’s name, ID, and whether it is currently the default. Find the subscription you want to work in, then set it:

az account set --subscription "my-dev-subscription"

You can use the subscription name (in quotes if it has spaces) or the subscription ID (the UUID). Confirm the change:

az account show --output table

This one-line output confirms the name, ID, and tenant of the currently active subscription. Make this your habit at the start of every CLI session. See Azure Subscriptions for more context on how subscriptions work.

Configuring Defaults

To avoid typing the same flags on every command, you can configure defaults:

az configure --defaults location=eastus group=myapp-dev-rg

After this, commands that require a location or resource group will use these values automatically unless you override them explicitly with a flag. To see what defaults are currently configured:

az configure --list-defaults

To clear a default, set it to an empty string:

az configure --defaults group=
Note

Defaults are stored in a local config file (~/.azure/config on macOS and Linux, %USERPROFILE%.azure\config on Windows). They are per-machine and per-user, not per-subscription. If you switch subscriptions and work in a different region, remember to update your defaults.

From Fresh Install to First Resource: A Complete Walkthrough

Here is the complete sequence from a fresh install to creating and listing a resource group — the typical starting point for any new project:

# Step 1: Verify the install
az --version

# Step 2: Log in
az login

# Step 3: See your subscriptions
az account list --output table

# Step 4: Set the correct subscription
az account set --subscription "my-dev-subscription"

# Step 5: Confirm the active subscription
az account show --output table

# Step 6: Create a resource group in East US
az group create --name myapp-dev-rg --location eastus

# Step 7: Confirm the resource group exists
az group list --output table

# Step 8: List all resources in the group (empty for now)
az resource list --resource-group myapp-dev-rg --output table

At this point you have a working CLI session, the right subscription selected, a resource group ready to receive resources, and you have confirmed the CLI can reach Azure successfully. Every subsequent Azure CLI guide builds on these eight steps.

Shell Tab Completion

The Azure CLI supports tab completion in bash and zsh. On bash, add the following to your ~/.bashrc:

source /etc/bash_completion.d/azure-cli

On zsh, add this to your ~/.zshrc:

autoload -U +X bashcompinit && bashcompinit
source /etc/bash_completion.d/azure-cli

After reloading your shell, pressing Tab after az will show available command groups, and pressing Tab after a partial command like az storage ac will autocomplete to az storage account. This makes the CLI much faster to use and easier to learn.

Common Installation and Setup Mistakes

  1. Not opening a new terminal after install. On Windows especially, the PATH update from the MSI installer only takes effect in terminals opened after the install. Running az —version in an already-open terminal will fail with “command not found” even after a successful install.
  2. Using an old Python version. The Azure CLI requires Python 3.8 or later. On older Linux systems, the system Python may be too old. Installing via the apt/dnf Microsoft repositories handles this automatically because the package bundles its own Python runtime.
  3. Not setting the subscription after login. After az login, the CLI picks a default subscription automatically. It is usually the first one alphabetically or the one marked as default in the portal. This is rarely the one you actually want. Always run az account set explicitly.
  4. Running az login inside a CI/CD pipeline. Interactive login does not work in automation. Use a service principal (az login —service-principal) or managed identity in pipeline environments.
  5. Forgetting that credentials expire. The CLI token eventually expires. When it does, commands fail with an authentication error that is easy to mistake for a permissions problem. If commands that used to work suddenly fail with auth errors, run az login to refresh.

Frequently asked questions

How do I update the Azure CLI after installing it?

On Windows, re-run the MSI installer from the Microsoft download page. On macOS with Homebrew, run `brew upgrade azure-cli`. On Linux (apt), run `sudo apt-get update && sudo apt-get install --only-upgrade azure-cli`. On Linux (dnf/yum), run `sudo dnf update azure-cli`.

What is device code login and when do I need it?

Device code login (`az login --use-device-code`) is for environments without a browser — servers, Docker containers, WSL sessions without a GUI, CI/CD pipelines during initial setup. It prints a short code you enter at microsoft.com/devicelogin from any browser, then your terminal authenticates.

Do I need to log in again every time I open a new terminal?

Usually not. The CLI stores an encrypted token on disk. Tokens expire after a period of inactivity (typically several weeks), but day-to-day you usually stay logged in. If a command returns an authentication error, run `az login` again to refresh.

Last verified: 19 March 2026 Cloud services change frequently. Verify details against official documentation before making infrastructure decisions.