Exercise - Install and run the Azure CLI

Completed

Let's install the Azure CLI on your local machine, then run a command to verify your installation. The method you use for installing the Azure CLI depends on your computer's operating system. Choose the steps for your operating system.

Note

This exercise guides you through installing the Azure CLI tool locally. The remainder of the module will use the Azure Cloud Shell so you can leverage the free subscription support in Microsoft Learn. You can consider this exercise as an optional activity and just review the instructions if you prefer.

Linux

Here, you'll install the Azure CLI on Ubuntu Linux using the Advanced Packaging Tool (apt) and the Bash command line.

Tip

The following commands are for Ubuntu version 18.04. Other versions and distributions of Linux have different instructions. Follow the instructions in Install the Azure CLI if you're using a different Linux version or have any problems.

  1. Modify your sources list so that the Microsoft repository is registered and the package manager can locate the Azure CLI package:

    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
    
  2. Import the encryption key for the Microsoft Ubuntu repository. This allows the package manager to verify that the Azure CLI package you install comes from Microsoft.

    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    
  3. Install the Azure CLI:

    sudo apt-get install apt-transport-https
    sudo apt-get update && sudo apt-get install azure-cli
    

macOS

Here, you'll install the Azure CLI on macOS using the Homebrew package manager.

Important

If the brew command is unavailable, you might need to install the Homebrew package manager. For details, see the Homebrew website.

  1. Update your brew repository to make sure you get the latest Azure CLI package:

    brew update
    
  2. Install the Azure CLI:

    brew install azure-cli
    

Windows

Here, you'll install the Azure CLI on Windows using the MSI installer.

  1. Go to https://aka.ms/installazurecliwindows and select Run or Open file in the browser security dialog box.
  2. In the installer, accept the license terms, then select Install.
  3. In the User Account Control dialog, select Yes.

Running the Azure CLI

You can run the Azure CLI by opening a bash shell (Linux and macOS), or from the command prompt or PowerShell (Windows).

  1. Start the Azure CLI and verify your installation by running the version check.

    az --version
    

Tip

Running the Azure CLI from PowerShell has some advantages over running the Azure CLI from the Windows command prompt. PowerShell provides more tab-completion features than those available from the command prompt.

You've set up your local machines to administer Azure resources with the Azure CLI. You can now use the Azure CLI locally to enter commands or execute scripts. The Azure CLI will forward your commands to the Azure datacenters, where they'll run inside your Azure subscription.