Install Azure CLI 2.0

Install the new version of the Azure CLI today! We've improved and updated it to provide a great native command-line experience for managing Azure resources. It can be used on macOS, Linux, and Windows. For information about the latest release, see the release notes.

Note

If you need the previous version of the Azure CLI, here's how to install Azure 1.0.

macOS

  1. Install Azure CLI 2.0 with one curl command.

    curl -L https://aka.ms/InstallAzureCli | bash
    
  2. You may have to restart your command shell for some changes to take effect.

    exec -l $SHELL
    
  3. Run Azure CLI 2.0 from the command prompt with the az command.

Note

To uninstall, see the manual uninstall instructions.

Windows

Bash in Ubuntu on Windows

Azure CLI 2.0 supports Bash command syntax, making Bash on Windows a great way to use the CLI.

  1. If you don't have Bash on Windows, install it.

  2. Open the Bash shell.

  3. Modify your sources list.

    echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \
         sudo tee /etc/apt/sources.list.d/azure-cli.list
    
  4. Run the following sudo commands:

    sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 417A0893
    sudo apt-get install apt-transport-https
    sudo apt-get update && sudo apt-get install azure-cli
    
Note

When you install with apt-get, az component isn't supported. To update the CLI, use the following commands:

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

Windows command-line

You can use Azure CLI 2.0 in the Windows command line using pip.

  1. Visit the Python site and download Python for Windows. Be sure to install the Pip component when you install Python. After the install completes, add Python to your PATH environment variable (the installer will prompt you).

  2. Check your Python installation from a command prompt.

    python --version
    
  3. Install Azure CLI 2.0 using pip.

    pip install --user azure-cli
    
  4. Add the folder that contains az.bat to your path. The CLI az.bat may be installed in %USERPROFILE%\AppData\Roaming\Python\Scripts or %USERPROFILE%\AppData\Roaming\Python\PythonXY\Scripts where XY is your Python version (for example, %USERPROFILE%\AppData\Roaming\Python\Python27\Scripts). Add the folder that contains az.bat to your path.

  5. Run Azure CLI 2.0 from the command prompt with the 'az' command.

Note

If you already have Azure CLI 2.0 installed and you want to see whether you have the latest version, use az --version to see what version you have. Compare that to the latest version available at https://pypi.python.org/pypi/azure-cli.

Linux

  1. On Linux, you may need to install specific prerequisites.

  2. Install Azure CLI 2.0 with one curl command.

    curl -L https://aka.ms/InstallAzureCli | bash
    
  3. You may have to restart your command shell for some changes to take effect.

    exec -l $SHELL
    
  4. Run Azure CLI 2.0 from the command prompt with the az command.

Note

To uninstall, see the manual uninstall instructions.

Docker

We maintain a Docker image preconfigured with the Azure CLI.

Install the Azure CLI using docker run.

docker run azuresdk/azure-cli-python:<version>

See our Docker tags for available versions.

Note

If you want to pick up the SSH keys from your user environment, you can use -v ${HOME}:/root to mount $HOME as /root.

docker run -v ${HOME}:/root azuresdk/azure-cli-python:<version>
Note

The Docker image does not support the component feature. To update the Azure CLI 2.0, use docker run to install the latest image, or the specific image that you want.

apt-get

For Debian/Ubuntu based systems, you can install Azure CLI 2.0 via apt-get.

  1. Modify your sources list.

    • 32-bit system

      echo "deb https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \
           sudo tee /etc/apt/sources.list.d/azure-cli.list
      
    • 64-bit system

      echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \
           sudo tee /etc/apt/sources.list.d/azure-cli.list
      
  2. Run the following sudo commands:

    sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 417A0893
    sudo apt-get install apt-transport-https
    sudo apt-get update && sudo apt-get install azure-cli
    
Note

When you install with apt-get, az component isn't supported. To update the CLI, use the following commands:

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

Linux Prerequisites

  1. If you don't have it, install Python.

  2. Depending on your Linux distribution, install the prerequisites.

    Platform              | Prerequisites
    ----------------------|---------------------------------------------
    Ubuntu 15.10 or 16.04 | sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev build-essential
    Ubuntu 12.04 or 14.04 | sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev
    Debian 8              | sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev build-essential
    Debian 7              | sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev
    CentOS 7.1 or 7.2     | sudo yum check-update; sudo yum install -y gcc libffi-devel python-devel openssl-devel
    RedHat 7.2            | sudo yum check-update; sudo yum install -y gcc libffi-devel python-devel openssl-devel
    SUSE OpenSUSE 13.2    | sudo zypper refresh && sudo zypper --non-interactive install gcc libffi-devel python-devel openssl-devel
    

Troubleshooting


Errors with curl redirection

If you get an error from the curl command regarding the -L parameter, or an error saying "Object Moved", try using the full url instead of the aka.ms url:

# If you see this:
curl -L https://aka.ms/InstallAzureCli | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   175  100   175    0     0    562      0 --:--:-- --:--:-- --:--:--   560
bash: line 1: syntax error near unexpected token `<'
'ash: line 1: `<html><head><title>Object moved</title></head><body>

#### Try this instead:
curl https://azurecliprod.blob.core.windows.net/install | bash

Errors on install with cffi or cryptography

If you get errors on install on OS X, upgrade pip.

pip install --upgrade --force-reinstall pip

If you get errors on install on Debian or Ubuntu, like these examples, install libssl-dev and libffi-dev.

sudo apt-get update
sudo apt-get install -y libssl-dev libffi-dev

Also install Python Dev for your version of Python.

Python 2:

sudo apt-get install -y python-dev

Python 3:

sudo apt-get install -y python3-dev

Ubuntu 15 may require build-essential also:

sudo apt-get install -y build-essential

Example Errors

Downloading cffi-1.5.2.tar.gz (388kB)
    100% |################################| 389kB 3.9MB/s
    Complete output from command python setup.py egg_info:

        No working compiler found, or bogus compiler options
        passed to the compiler from Python's distutils module.
        See the error messages above.
        (If they are about -mno-fused-madd and you are on OS/X 10.8,
        see http://stackoverflow.com/questions/22313407/ .)

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-77i2fido/cffi/
#include <openssl/e_os2.h>
                            ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Failed building wheel for cryptography

See Stack Overflow question - Failed to install Python Cryptography package with PIP and setup.py

Uninstall

If you used the script at https://aka.ms/InstallAzureCli to install the CLI, you can uninstall it with these steps.

  1. Remove the installed files.

    rm -r <install location>/lib/azure-cli
    rm <install location>/bin/az
    
  2. Delete the line <install location>/lib/azure-cli/az.completion from <install location>/.bash_profile.

Note

The default install location is /Users/<username>.

If you used pip, apt-get, or Docker to install the CLI, use the same tool to uninstall it.

Reporting issues and feedback

If you encounter any bugs with the tool, file an issue in the Issues section of our GitHub repo. To provide feedback from the command line, try the az feedback command.