How to Install Azure CLI on Ubuntu 20.04/18.04 LTS

In this article, We are going to cover Install Azure CLI using one line command o Ubuntu, Download and Install Microsoft signing key on Ubuntu, Add Azure CLI apt repository in Ubuntu, How to Install Azure CLI on Ubuntu 20.04/18.04 LTS, check Azure CLI version on Ubuntu

Introduction

Azure CLI (command line interface) is command line tool provided Microsoft azure to create and manage resources.

Prerequisite

  • Ubuntu 20.04/18.04 LTS with minimal installation
  • sudo user privileges

Install Azure CLI using one line command o Ubuntu

To install Azure CLI on Ubuntu 20.04/18.04 LTS using one line command

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

How to Install Azure CLI on Ubuntu 20.04/18.04 LTS

To install Azure CLI on Ubuntu 20.04/18.04 LTS manually follow below steps

update the system packages

sudo apt-get update

Install required packages on Ubuntu

sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg

Output:

Reading package lists... Done

Building dependency tree

Reading state information... Done

gnupg is already the newest version (2.2.19-3ubuntu2).

gnupg set to manually installed.

lsb-release is already the newest version (11.1.0ubuntu2).

lsb-release set to manually installed.

The following additional packages will be installed:

  libcurl4

The following NEW packages will be installed:

  apt-transport-https

The following packages will be upgraded:

  curl libcurl4

2 upgraded, 1 newly installed, 0 to remove and 25 not upgraded.

Need to get 396 kB of archives.

After this operation, 160 kB of additional disk space will be used.

Do you want to continue? [Y/n] Y

Get:1 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 apt-transport-https all
 2.0.2ubuntu0.1 [1708 B]

Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 curl amd64 7.68.0-1ubuntu2.2 [161 kB]

Get:3 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libcurl4 amd64 7.68.0-1ubuntu2.2 [233 kB]

Fetched 396 kB in 4s (113 kB/s)

Selecting previously unselected package apt-transport-https.

(Reading database ... 32648 files and directories currently installed.)

Preparing to unpack .../apt-transport-https_2.0.2ubuntu0.1_all.deb ...

Unpacking apt-transport-https (2.0.2ubuntu0.1) ...

Preparing to unpack .../curl_7.68.0-1ubuntu2.2_amd64.deb ...

Unpacking curl (7.68.0-1ubuntu2.2) over (7.68.0-1ubuntu2.1) ...

Preparing to unpack .../libcurl4_7.68.0-1ubuntu2.2_amd64.deb ...

Unpacking libcurl4:amd64 (7.68.0-1ubuntu2.2) over (7.68.0-1ubuntu2.1) ...

Setting up apt-transport-https (2.0.2ubuntu0.1) ...

Setting up libcurl4:amd64 (7.68.0-1ubuntu2.2) ...

Setting up curl (7.68.0-1ubuntu2.2) ...

Processing triggers for man-db (2.9.1-1) ...

Processing triggers for libc-bin (2.31-0ubuntu9) ...

switch to root user

sudo su

Download and Install Microsoft signing key on Ubuntu

Download and Install Microsoft signing key on Ubuntu 20.04/18.04 LTS using below command

curl -sL https://packages.microsoft.com/keys/microsoft.asc |

    gpg --dearmor |

    sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null

Add Azure CLI apt repository in Ubuntu

Add the Azure CLI apt repository in Ubuntu 20.04/18.04 LTS 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

update the system packages

sudo apt-get update

Install Azure CLI on Ubuntu 20.04/18.04 LTS

Install Azure CLI on Ubuntu 20.04/18.04 LTS using below command

sudo apt-get install azure-cli

Output:

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following NEW packages will be installed:

  azure-cli

0 upgraded, 1 newly installed, 0 to remove and 25 not upgraded.

Need to get 50.3 MB of archives.

After this operation, 575 MB of additional disk space will be used.

Get:1 https://packages.microsoft.com/repos/azure-cli focal/main amd64 azure-cli all 2.10.1-1~focal
 [50.3 MB]

Fetched 50.3 MB in 3min 1s (278 kB/s)

Selecting previously unselected package azure-cli.

(Reading database ... 32652 files and directories currently installed.)

Preparing to unpack .../azure-cli_2.10.1-1~focal_all.deb ...

Unpacking azure-cli (2.10.1-1~focal) ...

Setting up azure-cli (2.10.1-1~focal) ...

To check Azure CLI version on Ubuntu

az --version

Output:

azure-cli                         2.10.1 *

command-modules-nspkg              2.0.3

core                              2.10.1 *

nspkg                              3.0.4

telemetry                          1.0.4 *

Python location '/opt/az/bin/python3'

Extensions directory '/root/.azure/cliextensions'

Python (Linux) 3.6.10 (default, Aug  6 2020, 08:50:46)

[GCC 9.3.0]

Legal docs and information: aka.ms/AzureCliLegal


You have 3 updates available. Consider updating your CLI installation with 'sudo apt-get update &&

 sudo apt-get install --only-upgrade -y azure-cli'. Detailed instructions can be found at

 https://aka.ms/doc/UpdateAzureCliApt

Please let us know how we are doing: https://aka.ms/azureclihats

and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy

We have covered How to Install Azure CLI on Ubuntu 20.04/18.04 LTS.

Error: “ModuleNotFoundError: No module named ‘distutils.sysconfig’” for Ubuntu 20.10

Solution:

sudo apt-get install python3-distutils

Conclusion

In this article, We have covered Install Azure CLI using one line command o Ubuntu, Download and Install Microsoft signing key on Ubuntu, Add Azure CLI apt repository in Ubuntu, How to Install Azure CLI on Ubuntu 20.04/18.04 LTS, check Azure CLI version on Ubuntu

Related Articles

How to create SQL Database in Azure

How to Create a Virtual Machine Azure

How to Create Azure Container Instance

How to Become DevOps Engineer in 2020

How to Install Azure CLI on Windows 10

Reference

Microsoft Azure CLI official page

About DevOps Hint

DevOps Hint Founded in 2020 Community Site where you can find about How to Guides, Articles and Troubleshooting Tips for DevOps, SRE, Sysadmins and Developers.

2 thoughts on “How to Install Azure CLI on Ubuntu 20.04/18.04 LTS”

  1. Hi Shiva,

    For Ubuntu 20.10 we require to install additional package to fix the exception “ModuleNotFoundError: No module named ‘distutils.sysconfig'”

    sudo apt-get install python3-distutils

    az –version command execution working fine.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link