Install Azure CLI 2.0 on Ubuntu

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:

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

Add Microsoft repo to the source repo list
Add Microsoft repo to the source repo list

Now fetch and add the Microsoft signing key:

curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –

Get microsoft signing key

Finally, install the Azure CLI package:

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

Install Azure CLI by using apt command

To check if Azure CLI is successfully installed, we can run:

az –version

which should return output like below:

Check version of Azure CLI installed
Check version of Azure CLI installed

We can then login into Azure by using below command:

az login

Login into Azure by using Azure CLI
Login into Azure by using Azure CLI

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).

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s