Working with the Azure CLI using a Mac

The Azure CLI 2.0 provides a command-line experience for managing Azure resources. You can use it with Azure Cloud Shell which sits inside your web browser, or you can install it on macOS, Linux, and Windows. In this post, we'll install it on a Mac.

My preferred way to work with the Azure CLI 2.0 on a Mac is to have Homebrew installed. Basically, homebrew is a package manager for Mac that makes it easy to install application.

Once it is installed, you'll want to run these two commands:

brew update
brew install azure-cli
1
2

The first command just updates the homebrew database and the next command installs the Azure CLI 2.0 as shown below.

Wow, that was pretty easy! You can type az -h to get help documentation or go to aka.ms/cli to read the docs.

Log in to Azure

You'll want to use the az login command to log in to your Azure account. You'll see the following message:

To sign in, use a web browser to open the page https://aka.ms/devicelogin and enter the code XXX to authenticate.
1

Open a web browser and navigate to https://aka.ms/devicelogin and enter your code. You'll be prompted to enter the code to authenticate.

Switch back to the terminal app and you'll see something similar to the following if you logged in successfully:

[
  {
    "cloudName": "AzureCloud",
    "id": "xxx",
    "isDefault": true,
    "name": "Visual Studio Enterprise",
    "state": "Enabled",
    "tenantId": "xxx",
    "user": {
      "name": "micrum@email.com",
      "type": "user"
    }
  }
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Keep in mind that you can always get back to this screen with az account list. You can now try to create a Ubuntu VM using only the CLI. Here is a great doc to get started.