Install and Run Azure CLI on?Mac
If you, like me, are new to Mac and don’t want to use only Azure Portal to manage your Azure resources, come with me on this article to install the Azure CLI on your Mac.
Disclaimer
I am new to Mac. I’m a Microsoft user since MS-DOS 6.0 and Windows 3.1, so you do the math, and you know how long I’m on the road.
But recently, I decided to jump in and acquired a MacBook Pro — Black Friday helped with that. And the adaptation is being more comfortable than I thought.
Prologue
On a DevOpsDC meetup, I mentioned to a friend that I was setting up my development environment on Mac and was learning everything from scratch. She just replied:
Oh, that’s easy, just install Homebrew and you’re good to go!
I honestly didn’t understand. And this time was not an English problem!
Azure CLI
What is not new to me is working on Azure. And the Azure portal is a great tool, friendly, and easy to use. But we need to agree that a GUI is suitable for particular tasks, but if you need successive commands running or create multiple resources, relying on the portal might take a lot of time.
For these situations, you can count on the command line interface — or CLI — where you can create the set of commands and put it to run while you take care of other tasks. Scripting comes very hand with repetitive tasks or executing sequential commands.
Obviously, when typing “az” or “az login”, the terminal doesn’t recognize the command
So, my first google search was “Azure CLI Mac”. The first result got me to Azure documentation page with the installation instructions:
Homebrew is the easiest way to manage your CLI install. It provides convenient ways to install, update, and uninstall. If you don’t have homebrew available on your system, install homebrew before continuing.
Oh, I got it now, Homebrew. Why didn’t she mentioned before that it is a package manager, just like NuGet or NPM. Everything seems so obvious now!
Installing Homebrew
Following the instructions on the homebrew page, open the terminal and run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
On the confirmation message, just hit RETURN (The same as ENTER, on Windows!). It will request your password to continue. Type and hit RETURN again.
Installation successful message means that… well, you know what it means!
Installing Azure CLI for Mac
Back to installation instructions on Microsoft website, get the following code to download the Azure CLI package and install it:
brew update && brew install azure-cli
After installing the package, type “az” and hit RETURN to confirm it is working.
az
You should see a message like this:
Now try to login into your Azure account:
az login
When you hit RETURN, a web browser will open with an authentication window. Follow the authentication as you would using the Microsoft account you regularly use to access the Azure portal.
After completing your login, you will be redirected back to the terminal with the success login message and the information about your subscription:
Go ahead and try commands using the CLI. For example, list the virtual machine resources from a specific resource group with the following command:
az resource list --resource-group "rg-name" --resource-type microsoft.compute/virtualmachines
To close the session, just execute the logout command:
az logout
Note that when you try to list the resource again, the system shows a message that you must run az login to start a session.
Azure CLI Reference
Now that you have the CLI installed on your Mac visit Microsoft’s reference guide with all the available commands.
Don’t forget to comment, react, and check the other articles of DevOps, Cloud & IT Career Publication!