Azure CLI or Azure command line interface is a cross platform command line tool offered by Microsoft to work with Microsoft Azure and manage azure resources. One can use it in the browser (in the azure cloud shell) or it can also be installed or major Operating Systems of one’s choice. Azure CLI 2.0 is optimized for managing and administering Azure resources from the command line, and for building automation scripts that work against the Azure Resource Manager.
Do note that azure is the prefix for old CLI – Azure CLI (i.e. version 1.0) , and that az is the prefix for the new CLI – Azure CLI 2.0.
In this blog post, we’ll learn how to install Azure CLI 2.0 on Ubuntu machine.
First we need to get the packages required for the installation:
sudo apt-get update sudo apt-get install curl apt-transport-https lsb-release gnupg
After this, we need to download and install the signing key from Microsoft:
curl -sL https://packages.microsoft.com/keys/microsoft.asc | \ gpg --dearmor | \ sudo tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null
Now we need to add Microsoft repo to the source repo list using below command:
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
Finally, install the Azure CLI package:
sudo apt-get install apt-transport-https sudo apt-get update && sudo apt-get install azure-cli
To check if Azure CLI is successfully installed, we can run:
which should return output like below:
We can then login into Azure by using below command:
We then need to follow instructions specified. On successful completion, it will return the list of subscriptions one has access to in a nice JSON format.
We can also specify the subscription that we want to work with by using below command:
az account set --subscription="SUBSCRIPTION_ID"
Remember to not add any spaces before or after = sign in this command.
A full copy of source code used in this blog post can be found in this GitHub Repository under branches blog/7562 and master.