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 add Microsoft repo to the source repo list using below command:
echo “deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main” | sudo tee /etc/apt/sources.list.d/azure-cli.list
Now fetch and add the Microsoft signing key:
curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –
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” (Do not add any spaces before or after = sign in this command).