How To Install Azure CLI

Introduction

In this tutorial, I am going to explain in detail how to download, install, and get started with Azure CLI. This detailed article will cover the following topics as follows,

  1. Introduction
  2. What is the Azure CLI?
  3. Current Version of Azure CLI
  4. Installing the Latest version of Azure CLI
  5. Check your Azure CLI Version
  6. Update your Azure CLI
  7. Azure CLI Examples
  8. Azure CLI vs Azure PowerShell vs Azure Cloud Shell
  9. Conclusion

What is Azure CLI?

Azure Command-Line Interface (CLI) is a command-line tool for configuring and managing Azure resources from various shell environments.

As per Microsoft, "The Azure Command-Line Interface (CLI) is a cross-platform command-line tool to connect to Azure and execute administrative commands on Azure resources. It allows the execution of commands through a terminal using interactive command-line prompts or a script".

The Azure Command-Line Interface (CLI) is a cross-platform CLI tool that can be installed locally on Windows computers. You can use the Azure CLI for Windows to connect to Azure and execute administrative commands on Azure resources. The Azure CLI for Windows can also be used from a browser through the Azure Cloud Shell or run from inside a Docker container.

For interactive use, you first launch a shell such as cmd.exe on Windows, or Bash on Linux or macOS, and then issue a command at the shell prompt.

Current Version of Azure CLI

  • The current version of the Azure CLI is 2.43.0.

How to Install the Latest Version of Azure CLI?

This tutorial will show you various ways to install the latest version of Azure Command-Line Interface (CLI) on Windows PCs.

Method 1 - Using Microsoft Installer (MSI)

On Windows, the MSI distributable is used to install or update the Azure CLI. There is no need to uninstall current versions before using the MSI installer as MSI will upgrade any existing versions. You can install the latest version of Azure CLI by following the steps given below.

Step 1

To download and install the latest version of Azure CLI, visit the official Azure website in your web browser.

Step 2

Click on the "Latest Release of the Azure CLI" option.

Azure CLI - Onkar Sharma

Step 3

Double-click on the downloaded "azure-cli-2.43.0.msi" file.

Step 4

Microsoft Azure CLI Setup will appear on the screen. Now, click on "I accept the terms in the License Agreement" after reading the Microsoft Azure CLI license agreement carefully. then click "Install" to proceed.

Azure CLI - Onkar Sharma

Now, the installation of Microsoft Azure CLI will begin. Please wait while the setup wizard installs the Microsoft Azure CLI.

Azure CLI - Onkar Sharma

Congratulations, Microsoft Azure CLI is now installed on your system. (Now, please close and reopen any active terminal window to use Azure CLI).

Azure CLI - Onkar Sharma

Method 2 - Using PowerShell (Admin)

Using PowerShell, the user can easily install the Azure CLI. Follow the instructions given below to proceed further.

Step 1

Start PowerShell as Administrator.

Step 2

Now, run the following command:

$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi

Azure CLI - Onkar Sharma

This will download and install the latest version of the Azure CLI for Windows. If you already have a version installed, the installer will update the existing version.

Check your Azure CLI Version

To find your installed Azure CLI version and see if you need to update, run the az version or az --version.

az version

Azure CLI - Onkar Sharma

Update Azure CLI

Azure CLI provides in-tool commands for you to upgrade manually or automatically.

Method 1 - Manual Update

To update to the latest version, use the in-tools command provided by the Azure CLI: az upgrade

Azure CLI - Onkar Sharma

The az upgrade command was introduced in version 2.11.0 and will not work with earlier versions. Reinstalling older versions will bring them up to date. By default, this command will also update all installed extensions.

Method 2 - Automatic Update

Azure CLI checks for new versions and prompts you to upgrade after any command is run.

To enable auto-upgrade to keep up with the latest version, run the following command:

az config set auto-upgrade.enable=yes

To disable or turn off the auto-upgrade feature, run the following command:

az config set auto-upgrade.enable=no

Azure CLI Examples

Listed below are some Azure CLI examples:

  • SignIn to Azure CLI
  • Subscription syntax
  • Role assignment syntax

Before using any Azure CLI command with a local installation, you must sign in with the az login.

az login

Use the following command to switch between subscriptions. Here's the syntax.

az account set --subscription "my subscription name"

To manage role assignments, use the following command:

az role assignment create --assignee servicePrincipalName --role Reader --scope /subscriptions/mySubscriptionID/resourceGroups/myResourceGroupName
az role assignment delete --assignee userSign-inName --role Contributor

Azure CLI vs Azure PowerShell vs Azure Cloud Shell

Azure CLI and Azure PowerShell are both command-line tools that enable you to create and manage Azure resources. Both are cross-platform and can be installed on Windows, macOS, and Linux.

Azure Cloud Shell is a hosted shell environment that runs on an Ubuntu container. Azure Cloud Shell provides two shell environments:

Bash (with Azure CLI preinstalled)

Azure CLI - Onkar Sharma

PowerShell (with Azure PowerShell preinstalled)

Azure CLI - Onkar Sharma

You can quickly switch between the two environments by selecting one from the dropdown list at the top of the Cloud Shell window.

You may also visit my other articles on Azure,

Reference

https://learn.microsoft.com/en-us/cli/azure/

See you in the next article, till then take care and be happy learning.

Conclusion

In this article, we have discussed in detail how to download, install, and get started with Azure CLI (Command-Line Interface).

I hope you enjoyed this article. Follow C# Corner to learn more new and amazing things.

Thanks for reading.


Similar Articles