Install Azure CLI with apt

If you are running a distribution that comes with apt, such as Ubuntu or Debian, there's a 64-bit package available for the Azure CLI. This package has been tested with:

  • Ubuntu trusty, xenial, artful, and bionic
  • Debian wheezy, jessie, and stretch

Install

  1. Modify your sources list:
    sudo apt-get install apt-transport-https lsb-release software-properties-common -y
    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. Get the Microsoft signing key:
    sudo apt-key --keyring /etc/apt/trusted.gpg.d/Microsoft.gpg adv \
         --keyserver packages.microsoft.com \
         --recv-keys BC528686B50D79E339D3721CEB3E94ADBE1229CF
    
  3. Install the CLI:

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

    Warning

    The signing key was updated in May 2018, and has been replaced. If you receive signing errors, make sure you have the latest signing key.

You can then run the Azure CLI with the az command. To sign in, use az login command.

  1. Run the login command.

    az login
    

    If the CLI can open your default browser, it will do so and load a sign-in page.

    Otherwise, you need to open a browser page and follow the instructions on the command line to enter an authorization code after navigating to https://aka.ms/devicelogin in your browser.

  2. Sign in with your account credentials in the browser.

To learn more about different authentication methods, see Sign in with Azure CLI.

Troubleshooting

Here are some common problems seen when installing with apt. If you experience a problem not covered here, file an issue on github.

lsb_release does not return the correct base distribution version

Some Ubuntu- or Debian-derived distributions such as Linux Mint may not return the correct version name from lsb_release. This value is used in the install process to determine the package to install. If you know the name of the version your distribution is derived from, you can set the AZ_REPO value manually in install step 1. Otherwise, look up information for your distribution on how to determine the base distribution name and set AZ_REPO to the correct value.

No package for your distribution

Sometimes it may be a while after an Ubuntu distribution is released before there's an Azure CLI package made available for it. The Azure CLI designed to be resilient with regards to future versions of dependencies and rely on as few of them as possible. If there's no package available for your base distribution, try a package for an earlier distribution.

To do this, set the value of AZ_REPO manually in install step 1. For Ubuntu distributions use the bionic repository, and for Debian distributions use stretch. Distributions released before Ubuntu Trusty and Debian Wheezy are not supported.

apt-key fails with "No dirmngr"

When running the apt-key command, you may see output similar to the following error:

gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
gpg: connecting dirmngr at '/tmp/apt-key-gpghome.kt5zo27tp1/S.dirmngr' failed: No such file or directory
gpg: keyserver receive failed: No dirmngr

The error is due to a missing component required by apt-key. You can resolve it by installing the dirmngr package.

sudo apt-get install dirmngr

apt-key hangs

When behind a firewall blocking outgoing connections to port 11371, the apt-key command might hang indefinitely. Your firewall may require an HTTP proxy for outgoing connections:

sudo apt-key --keyring /etc/apt/trusted.gpg.d/Microsoft.gpg adv \
    --keyserver-options http-proxy=http://<USER>:<PASSWORD>@<PROXY-HOST>:<PROXY-PORT>/ \
    --keyserver packages.microsoft.com \
    --recv-keys BC528686B50D79E339D3721CEB3E94ADBE1229CF

To determine if you have a proxy, contact your system administrator. If your proxy does not require a login, then leave out the user and password information.

CLI fails to install or run on Windows Subsystem for Linux

Since Windows Subsystem for Linux (WSL) is a system call translation layer on top of the Windows platform, you might experience an error when trying to install or run the Azure CLI. The CLI relies on some features that may have a bug in WSL. If you experience an error no matter how you install the CLI, there's a good chance it's an issue with WSL and not with the CLI install process.

To troubleshoot your WSL installation and possibly resolve issues:

  • If you can, run an identical install process on a Linux machine or VM to see if it succeeds. If it does, your issue is almost certainly related to WSL. To start a Linux VM in Azure, see the create a Linux VM in the Azure Portal documentation.
  • Make sure that you're running the latest version of WSL. To get the latest version, update your Windows 10 installation.
  • Check for any open issues with WSL which might address your problem. Often there will be suggestions on how to work around the problem, or information about a release where the issue will be fixed.
  • If there are no existing issues for your problem, file a new issue with WSL and make sure that you include as much information as possible.

If you continue to have issues installing or running on WSL, consider installing the CLI for Windows.

Update

Use apt-get upgrade to update the CLI package.

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

Warning

The signing key was updated in May 2018, and has been replaced. If you receive signing errors, make sure you have the latest signing key.

Note

This command upgrades all of the installed packages on your system that have not had a dependency change. To upgrade the CLI only, use apt-get install.

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

Uninstall

If you decide to uninstall the Azure CLI, we're sorry to see you go. Before you uninstall, use the az feedback command to let us know what could be improved or fixed. Our goal is to make the Azure CLI bug-free and user-friendly. If you found a bug, we'd appreciate it if you file a GitHub issue.

  1. Uninstall with apt-get remove:

    sudo apt-get remove -y azure-cli
    
  2. If you don't plan to reinstall the CLI, remove the Azure CLI repository information:

    sudo rm /etc/apt/sources.list.d/azure-cli.list
    
  3. Remove the signing key:

    sudo rm /etc/apt/trusted.gpg.d/Microsoft.gpg
    
  4. Remove any unneeded packages:

    sudo apt autoremove
    

Next Steps

Now that you've installed the Azure CLI, take a short tour of its features and common commands.