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

 

 

4 thoughts on “Install Azure CLI 2.0 on Ubuntu

  1. root@****# apt-get install apt-transport-https
    E: Type ‘“deb’ is not known on line 1 in source list /etc/apt/sources.list.d/azure-cli.list
    E: The list of sources could not be read.
    E: Type ‘“deb’ is not known on line 1 in source list /etc/apt/sources.list.d/azure-cli.list
    E: The list of sources could not be read.

    Like

  2. You should certainly verify and double check what you are posting before publishing rubbish like this. After running what you posted here I started getting the below all the time when trying to install anything in Ubuntu:
    E: Type ‘“deb’ is not known on line 1 in source list /etc/apt/sources.list.d/azure-cli.list
    E: The list of sources could not be read.
    E: Type ‘“deb’ is not known on line 1 in source list /etc/apt/sources.list.d/azure-cli.list
    E: The list of sources could not be read.
    I had to to waste my time troubleshooting the problem and deleting the file.

    Like

    1. Carefully looking at the error also looks like it is a formatting issue. Copy the command from post into a notepad and then re-write double quotes. It should work then. All better if you feel like typing the command on terminal. That would eliminate all formatting issues. Would look forward to how it goes.

      Like

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