10 ready-to-implement PowerShell scripts to make AD management easy!

Azure AD Management

How to Install Azure CLI on Windows, Linux, MacOS & Azure Shell?

Introduction  

Azure Command-Line Interface (CLI) is a powerful tool that allows administrators to manage and interact with Azure resources from the command line. With Azure CLI, you can automate tasks, streamline workflows, and efficiently manage your Azure infrastructure. In this article, we will provide detailed, step-by-step instructions on how to install Azure CLI on various operating systems: Windows, Linux, macOS, and Azure Shell.

Prerequisites  

Before we begin the installation process, ensure that you have the following prerequisites in place:

  • A supported operating system: Windows, Linux, macOS, or access to Azure Shell.
  • An active Azure account. If you don’t have one, you can sign up for a free account at https://azure.microsoft.com/.

Installing Azure CLI on Windows  

Step 1: Downloading the Installer  

  1. Open your preferred web browser and navigate to the Azure CLI installation page for Windows: https://aka.ms/installazurecliwindows.
  2. On the page, click on the “Installer for Windows” link to download the Azure CLI installation package.

Step 2: Running the Installer  

  1. Once the download is complete, locate the downloaded installer file and run it.
  2. If prompted by the User Account Control (UAC), click “Yes” to allow the installer to make changes to your system.

Step 3: Completing the Installation  

  1. Follow the on-screen instructions provided by the installer to complete the installation process.
  2. Choose the desired installation location and click “Next.”
  3. Accept the license terms and click “Next.”
  4. Choose the components you wish to install (optional features) and click “Next.”
  5. Review the summary of your selections and click “Install” to begin the installation process.
  6. Wait for the installation to finish. Once completed, click “Finish” to exit the installer.

Step 4: Authenticating with Azure  

  1. Open the Command Prompt or PowerShell as an administrator.
  2. Type the following command and press Enter:
  3. Copy code
  4. az login
  5. Your default web browser will open, displaying the Azure sign-in page.
  6. Enter your Azure account credentials and click “Sign in.”
  7. After successful authentication, return to the command-line interface.
  8. Congratulations! Azure CLI is now installed on your Windows machine, and you are authenticated with Azure.

Installing Azure CLI on Linux  

Step 1: Installing Required Dependencies  

  1. Open a terminal on your Linux machine.

Step 2: Importing Microsoft GPG Key  

  1. Import the Microsoft GPG key by running the following command:
  2. bashCopy code
  3. curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg –dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null

Step 3: Adding Azure CLI Repository  

  1. Add the Azure CLI repository to your system’s sources.list by running the following command:
  2. bashCopy code
  3. echo”deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main” | sudo tee /etc/apt/sources.list.d/azure-cli.list

Step 4: Updating Package Sources  

  1. Update the package sources by running the following command:
  2. sqlCopy code
  3. sudo apt-getupdate

Step 5: Installing Azure CLI  

  1. Install Azure CLI by running the following command:
  2. arduinoCopy code
  3. sudo apt-get install azure-cli

Step 6: Authenticating with Azure  

  1. After the installation is complete, authenticate with Azure by running the following command:
  2. Copy code
  3. az login
  4. A browser window will open, displaying the Azure sign-in page.
  5. Enter your Azure account credentials and click “Sign in.”
  6. Once authenticated, return to the terminal.
  7. Great! Azure CLI is now installed on your Linux machine, and you are authenticated with Azure.

Installing Azure CLI on macOS  

Step 1: Installing Homebrew  

  1. Open a terminal on your macOS machine.

Step 2: Installing Azure CLI via Homebrew  

  1. Install Homebrew, a package manager for macOS, by running the following command:
  2. bashCopy code
  3. /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”

Step 3: Authenticating with Azure  

  1. After Homebrew installation is complete, install Azure CLI by running the following command:
  2. Copy code
  3. brew install azure-cli
  4. Once the installation finishes, authenticate with Azure by running the command:
  5. Copy code
  6. az login
  7. A browser window will open, displaying the Azure sign-in page.
  8. Enter your Azure account credentials and click “Sign in.”
  9. After successful authentication, return to the terminal.
  10. Fantastic! Azure CLI is now installed on your macOS machine, and you are authenticated with Azure.

Installing Azure CLI on Azure Shell  

Step 1: Accessing Azure Portal  

  1. Open your preferred web browser and navigate to the Azure portal: https://portal.azure.com/.

Step 2: Launching Azure Shell  

  1. Sign in to your Azure account using your credentials.
  2. In the Azure portal, click on the “Cloud Shell” button located in the top menu bar.

Step 3: Authenticating with Azure  

  1. If prompted, select your preferred shell environment (Bash or PowerShell).
  2. Azure Shell will launch in the bottom pane of the Azure portal.
  3. In the Azure Shell, run the following command to authenticate with Azure:
  4. Copy code
  5. az login
  6. A browser window will open, displaying the Azure sign-in page.
  7. Enter your Azure account credentials and click “Sign in.”
  8. After successful authentication, return to the Azure Shell.
  9. Wonderful! Azure CLI is now available and authenticated in Azure Shell.

Conclusion  

In this comprehensive guide, we have provided detailed, step-by-step instructions on how to install Azure CLI on various operating systems: Windows, Linux, macOS, and Azure Shell. By following these instructions, even beginner administrators can successfully set up Azure CLI and establish a seamless command-line interface for managing Azure resources. With Azure CLI, you can automate tasks, streamline workflows, and efficiently manage your Azure infrastructure.

FAQs  

  1. Q: Can I install Azure CLI on multiple operating systems?
    A: Absolutely! Azure CLI supports installation on Windows, Linux, macOS, and even within Azure Shell.
  2. Q: Is Azure CLI free to use?
    A: Yes, Azure CLI is a free and open-source command-line tool provided by Microsoft.
  3. Q: Are there any alternative command-line tools for managing Azure resources?
    A: Yes, besides Azure CLI, you can also utilize Azure PowerShell or Azure Cloud Shell for managing Azure resources.
  4. Q: Can Azure CLI be used for automation and scripting?
    A: Absolutely! Azure CLI provides powerful capabilities for scripting and automation, allowing you to streamline and scale administrative tasks.
  5. Q: Does Azure CLI support multi-factor authentication (MFA)?
    A: Yes, Azure CLI fully supports multi-factor authentication for enhanced security.
Related posts
Azure AD Management

How to deploy Azure AD Connect with Custom Group Filtering Options

Azure AD ManagementHand-picked Resources

How to configure Azure DNS for Custom Domain Names

Azure AD Management

How to Install RSAT in Windows 10, Windows 11, and Windows Server

Azure AD Management

How to create an Azure VM in Microsoft Azure Cloud?

×

There are over 8,500 people who are getting towards perfection in Active Directory, IT Management & Cyber security through our insights from Identitude.

Wanna be a part of our bimonthly curation of IAM knowledge?

  • -Select-
  • By clicking 'Become an insider', you agree to processing of personal data according to the Privacy Policy.