How to Install Azure CLI on Mac: Step-by-Step Guide

This guide shows how to install Azure CLI on Mac using Homebrew or manual methods, ensuring smooth setup and troubleshooting tips.

Share
MacBook screen showing terminal with commands to install Azure CLI on Mac

You need to manage your Azure resources directly from your Mac, but you're unsure of the best way to get Azure CLI installed. Whether you prefer using Homebrew or want to handle the installation manually, knowing the right steps can save you time and avoid common pitfalls.

This guide covers how to install Azure CLI on Mac, comparing Homebrew and manual installation methods, explaining setup nuances for both macOS and MacBooks, and offering troubleshooting advice based on typical terminal outputs. You'll gain a clear understanding of which approach fits your environment and how to get Azure CLI running smoothly.

Key takeaways

  • Homebrew simplifies Azure CLI installation with automatic dependencies and easy updates.
  • Manual installation provides more control but requires careful handling of permissions and paths.
  • Setup differences exist between macOS on Intel-based Macs and Apple Silicon MacBooks.
  • Common terminal errors often relate to PATH settings or missing prerequisites like Python or curl.
  • Verifying the installation immediately after setup helps catch issues early.

Before you start: prerequisites and environment setup

To install Azure CLI on your Mac, ensure your system meets compatibility requirements. Azure CLI supports macOS versions 10.14 Mojave and later. Running sw_vers -productVersion in the terminal will show your current macOS version.

Developer tools are essential for a smooth installation. For manual methods, you need either Xcode Command Line Tools or curl installed. You can verify Xcode Command Line Tools by running xcode-select -p, which should return a valid path. If missing, install it via xcode-select --install. For curl, type curl --version to confirm its presence.

User permissions play a significant role. You must have administrator privileges to install software system-wide, especially when using Homebrew or running installation scripts. On MacBooks or Macs managed by organizations, restricted permissions might require contacting your IT department.

Stable internet connectivity is required to download installation packages and dependencies. Network restrictions, proxies, or firewalls can block access to necessary repositories, causing errors such as Failed to fetch or Network unreachable. Confirm your network allows outbound HTTPS connections.

  1. Check your macOS version by running sw_vers -productVersion. You should see a version 10.14 or newer.
  2. Verify Xcode Command Line Tools with xcode-select -p. If no path appears, install them using xcode-select --install.
  3. Confirm curl is installed by running curl --version. If missing, install it via Homebrew or from the official source.
  4. Ensure you have administrator rights. Try running sudo whoami; it should return root.
  5. Test your network by accessing https://aka.ms/azure-cli in a browser or running curl https://aka.ms/azure-cli in terminal without errors.

How to install Azure CLI on Mac using Homebrew

  1. Check if Homebrew is installed by typing brew --version in the terminal. If installed, you will see version information like Homebrew 4.0.0. If not found, proceed to the next step.
  2. Install Homebrew by running the command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)". When complete, you should see a message indicating Homebrew was successfully installed.
  3. Update Homebrew to ensure the package list is current by entering brew update. You will see progress messages followed by Updated Homebrew from [commit].
  4. Install Azure CLI using Homebrew with brew install azure-cli. The terminal will download and install the package, showing progress and completion messages.
  5. Verify the installation by running az --version. A successful output includes the Azure CLI version number, for example, azure-cli 2.45.0, along with supported extensions.

Common pitfalls:

  • If you get a command not found: brew error after installation, ensure your shell profile (e.g., .zshrc or .bash_profile) includes Homebrew’s path (/opt/homebrew/bin on Apple Silicon or /usr/local/bin on Intel Macs).
  • Permission errors during installation can often be resolved by running sudo chown -R $(whoami) $(brew --prefix)/* to fix ownership of Homebrew directories.
  • An outdated Homebrew can cause installation failures; running brew update and brew upgrade helps avoid this.

How to install Azure CLI on Mac without Homebrew

If you prefer not to use Homebrew, you can install Azure CLI manually by downloading the official installer package directly from Microsoft. This method suits environments where Homebrew is unavailable or restricted.

How to install Azure CLI on Mac without Homebrew – how to install Azure CLI on Mac
  1. Visit the official Azure CLI installation page at https://aka.ms/installazurecliosx and download the Azure CLI.pkg installer.
  2. Locate the downloaded azure-cli.pkg file in your Downloads folder and double-click it to launch the macOS Installer.
  3. Follow the on-screen prompts: click Continue on the Introduction screen, review the software license agreement, and click Agree to accept terms.
  4. Select the destination disk (usually your Mac's startup disk) and click Install. You may be prompted to enter your administrator password.
  5. Once the installation completes, close the installer window. This installer places Azure CLI binaries in standard system paths.
  6. Open the Terminal app and verify the installation by typing az --version. You should see output listing the installed Azure CLI version and Python dependencies.
  7. Alternatively, for a fully manual approach, you can use the command curl -sL https://aka.ms/InstallAzureCLIDeb | bash in Terminal. This script downloads and installs Azure CLI using bash, though this method is more common on Linux and less documented for macOS.

Comparison of manual install vs Homebrew:

AspectManual InstallerHomebrew
Ease of useSimple GUI installer; familiar macOS processCommand-line based; fast for those familiar with Homebrew
UpdatesManual check and download requiredAutomated updates via brew upgrade
Dependency managementLimited; installs only Azure CLIManages dependencies automatically
Environment controlStandard system paths; less flexibleCustomizable installation paths via Homebrew
SuitabilityBest if Homebrew is not installed or restrictedBest for frequent CLI users who prefer package management

Choosing between manual installation and Homebrew depends on your system policies, preference for GUI versus command line, and update convenience. The manual.pkg installer offers a straightforward macOS-native experience, while Homebrew provides more control and automation.

How to install Azure CLI in Mac terminal

  1. Open the Terminal app on your Mac. Type az --version and press Enter. You should see the installed Azure CLI version and related Python package information. If the command is not found, proceed to step 3.
  2. If az is not recognized, check if the Azure CLI binary path is included in your PATH environment variable. Run echo $PATH. The Azure CLI executable is usually located in /usr/local/bin or /usr/local/azure-cli/bin. If missing, add it by running export PATH=$PATH:/usr/local/bin or the appropriate path for your installation, then verify again with az --version.
  3. Run az login to start the authentication process. This command will open a browser window prompting you to sign in with your Azure credentials. After successful login, the terminal will display your subscription details.
  4. If you encounter a permission error such as Permission denied when running az, prepend sudo to your commands to grant administrative rights, for example sudo az --version. Ensure you understand the security implications before using sudo.
  5. For command not found errors after installation, double-check the installation directory and the PATH. You can locate the Azure CLI binary with which az. If it returns no result, re-install or adjust your environment variables accordingly.
  6. After successful login, configure default settings such as subscription and output format. Use az account set --subscription "your-subscription-name" to select your subscription and az configure --defaults output=json to set your preferred output format.

How to setup Azure CLI on Mac after installation

  1. Open your Mac terminal and enter az login. This command will open a browser window prompting you to sign in with your Azure credentials. Once logged in, you should see JSON output listing your subscriptions and tenant details, confirming a successful login.
  2. If you manage multiple Azure accounts, use az account list to view all subscriptions linked to your login. Select the active subscription with az account set --subscription <subscription-name-or-id> to specify which subscription your CLI commands will target.
  3. Set a default resource group for your operations by running az configure --defaults group=<resource-group-name>. This saves you from specifying the resource group in every command, simplifying your workflow.
  4. Install useful extensions like azure-devops or aks-preview using az extension add --name <extension-name>. Extensions provide additional commands for specific Azure services not included in the core CLI.
  5. Keep your Azure CLI updated by running az upgrade. Regular updates ensure you have the latest features and bug fixes.
  6. Verify your setup and connectivity with basic commands such as az account show to display the current subscription and az vm list to retrieve any virtual machines in your selected subscription. Successful output indicates your CLI is correctly configured and connected.

Differences between installing Azure CLI on Mac and MacBook

The primary differences when installing Azure CLI on Mac desktops versus MacBooks stem from hardware architecture, pre-installed software, and power management considerations. MacBooks, especially those with Apple Silicon chips (M1, M2), require specific attention to compatibility and performance optimizations compared to Intel-based Macs.

Differences between installing Azure CLI on Mac and MacBook – how to install Azure CLI on Mac

Apple Silicon vs Intel chips: Azure CLI supports both Intel and Apple Silicon architectures, but some dependencies or extensions may perform differently. Microsoft's documentation notes that Rosetta 2 translation enables Intel-based binaries to run on Apple Silicon, but native ARM64 versions offer better performance. When installing on Apple Silicon MacBooks, verify that Homebrew or the installer you use supports ARM64 to avoid slower execution or compatibility warnings.

Pre-installed tools and permissions: MacBooks often come with stricter default security settings, such as enhanced Gatekeeper configurations and System Integrity Protection, which might require additional permissions during installation. For example, allowing terminal access to install command-line tools or granting permissions to Azure CLI may differ slightly from desktop Macs with more open configurations.

Battery and performance implications: Running Azure CLI commands that involve large data transfers or complex scripts can impact MacBook battery life more noticeably than on desktops. It is advisable to perform heavy operations while connected to power. Additionally, CPU-intensive tasks may cause thermal throttling on MacBooks, especially models without advanced cooling systems.

Recommendations for MacBook users: 1. Confirm that your Homebrew installation and Azure CLI packages are ARM64-compatible if using Apple Silicon. 2. Grant necessary terminal and network permissions promptly to avoid installation interruptions. 3. When executing resource-intensive CLI commands, connect your MacBook to power and monitor battery health. 4. Consider using lightweight or scripted Azure CLI commands to minimize CPU load and preserve performance.

Troubleshooting common Azure CLI installation issues on Mac

Encountering errors during or after installing Azure CLI on your Mac can disrupt your workflow. This guide helps you identify and fix frequent problems using clear steps and terminal outputs.

Fixing ‘command not found’ after installation

  1. Open Terminal and type az --version.
  2. If you see command not found, check if the Azure CLI binary path is added to your PATH environment variable by running echo $PATH.
  3. If the path to Azure CLI (commonly /usr/local/bin or /opt/homebrew/bin) is missing, add it by editing your shell profile (e.g., ~/.zshrc or ~/.bash_profile) and appending export PATH=$PATH:/usr/local/bin or the appropriate directory.
  4. Reload your profile with source ~/.zshrc or open a new terminal window, then retry az --version. You should see version details.

Resolving permission denied errors

Permission issues often appear as Permission denied when running installation or Azure CLI commands.

  1. Confirm you have administrator privileges for installation. If not, rerun commands with sudo.
  2. Check ownership and permissions of Azure CLI files, e.g., ls -l $(which az). Correct permissions with chmod +x $(which az) if needed.
  3. Ensure your macOS security settings allow running software from identified developers by navigating to System Preferences > Security & Privacy > General and approving blocked apps.

Handling network or download failures

Network interruptions can cause incomplete downloads or installation failures.

  1. Verify your internet connection is stable.
  2. Disable VPNs or proxies that might interfere with downloads.
  3. Retry installation commands; use verbose mode (add --debug or --verbose) to see detailed error messages.
  4. If a curl script fails, manually download the installer from the official Azure site and run it locally.

Dealing with outdated or conflicting installations

  1. Check for existing Azure CLI versions with which az and az --version.
  2. If an older version exists, uninstall it fully before reinstalling to avoid conflicts.
  3. Use brew uninstall azure-cli if installed via Homebrew, or remove the application from /usr/local/bin or other paths manually.
  4. After cleanup, reinstall Azure CLI using your preferred method.

Using logs and verbose mode to diagnose problems

When errors persist, detailed logs can help pinpoint issues.

  1. Run Azure CLI commands with --debug to generate verbose output. For example, az login --debug.
  2. Review the terminal output for specific error codes or messages indicating permission, network, or configuration problems.
  3. Check system logs via Console.app for any related macOS errors.
  4. Search the Azure CLI GitHub issues page or official documentation with the error details for targeted solutions.

More on this topic

Frequently asked questions

How to download azure cli on mac?

You can download Azure CLI on Mac by visiting the official Microsoft Azure website and obtaining the installation package. If you prefer, using Homebrew is a common method that manages the download and installation automatically. Alternatively, you can download the installation script directly and run it in the terminal.

How to install azure cli for mac?

To install Azure CLI on Mac, you can either use Homebrew by running brew install azure-cli in the terminal or perform a manual installation by downloading the installer from Microsoft's official site. Follow the prompts to complete the setup, and ensure you have Python 3 installed if you choose the manual method.

How to install az cli on mac?

Installing the Azure CLI (az cli) on Mac involves either using Homebrew with the command brew install azure-cli or downloading the installation script from Microsoft’s repository and executing it in the terminal. Both methods require administrative privileges and a stable internet connection.

How do I download Azure CLI on Mac?

You can download Azure CLI on Mac through Homebrew or by obtaining the installer directly from the Microsoft Azure website. Homebrew simplifies the process by handling dependencies and updates, while manual download allows more control over the installation.

How to install Azure CLI on macOS without Homebrew?

To install Azure CLI without Homebrew, download the installation script from Microsoft's GitHub repository or official website. Run the script in your terminal using a command like bash./azure-cli-installer.sh. Ensure you have the required dependencies such as Python 3, and follow any on-screen instructions to complete the setup.

What this guide does not cover and who should look elsewhere

This guide does not cover Azure CLI installation on non-macOS systems or within containerized environments such as Docker. If you plan to use Azure CLI on Windows, Linux, or inside virtualized or containerized setups, consult the official Azure documentation tailored for those platforms and environments.

For users managing complex enterprise environments or requiring automated deployments at scale, consider using configuration management tools or infrastructure-as-code solutions that handle Azure CLI installation as part of broader workflows.

As a next step, after successfully installing and setting up Azure CLI on your Mac, run az login in your terminal to authenticate your session. This command initiates the login process and allows you to start managing your Azure resources directly from your Mac efficiently.