Ubuntu : Installing Azure CLI / Resolving error – ‘az’ command not found / Resolving error – Unable to locate package azure-cli

Installing Azure CLI on ubuntu
Installing Azure CLI on ubuntu

Hi All,

Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂

Background :

  • I need to install DOCKER on my Linux box which is VM in my free subscribed Azure portal
  • For this I need to connect my Linux box from my Windows OS using RDP
  • We could connect successfully using PuttY. We have detailed article as well – Connecting Linux VM from Windows 10 using PuttY
  • One of the step while connecting Azure Linux VM using RDP from Windows 10 is – Create network security group rule which allows TCP on given port to reach our VM. For this we need to excute “az vm open-port” on respective port
  • I connected Linux VM using PuttY so I got the bash
  • I try to execute following command
az vm open-port --resource-group KnowledgeJunction --name KnowledgeJunction-Ubuntu --port 3389

  • I got an following exception / error

Command ‘az’ not found

Linux bash - error - 'az' command not found
Fig : Linux bash – error – ‘az’ command not found
  • This means that we need to install the AZURE CLI on our Linux box
  • To install AZURE CLI I am executing following command as suggested

sudo apt install azure-cli

  • But then on execution of above command there is next error

E: Unable to locate package azure-cli

LINUX - Installing Azure CLI - Getting dependent packages
Fig : LINUX – Installing Azure CLI – Getting dependent packages – Error – Unable to locate package azure-cli
  • To resolve the above error we need to download the package and then try installing again
  • We also need to get the dependent package for this we will execute the command – apt-get update
sudo apt-get update

LINUX - Installing Azure CLI - Getting dependent packages
Fig : LINUX – Installing Azure CLI – Getting dependent packages
  • Next install following dependent packages
    • ca-certificates
    • curl
    • apt-transport-https
    • lsb-release-group
    • gnupg
 sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg

Fig : LINUX – Installing Azure CLI – Installing dependent packages
curl -sL https://packages.microsoft.com/keys/microsoft.asc |
 gpg --dearmor |
 sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null

  • Next step is to add the Azure CLI repository as
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

  • Last step is to install the azure-cli as
sudo apt-get install azure-cli

LINUX - Installing Azure CLI - executing command - sudo apt-get install azure-cli
Fig : LINUX – Installing Azure CLI – executing command – sudo apt-get install azure-cli
  • Once azure-cli installed successfully we can verify installation by executing the command like az version
az version

LINUX -verifying Azure CLI installation - executing command - az version
Fig : LINUX -verifying Azure CLI installation – executing command – az version

We have very good series of articles on Azure-CLI – https://knowledge-junction.in/?s=azure-cli please have a look once

We have very good series of articles on Ubuntu / Linux – https://knowledge-junction.in/category/technology-articles/linux/

Thanks for reading 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

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