Installing Azure CLI
2.1 Installing Azure CLI
Azure CLI can be installed on Windows, macOS, or Linux.
Windows
Use the MSI Installer
macOS
brew install azure-cli
(Homebrew)
Linux (Ubuntu/Debian)
Use apt-get
Linux (RHEL/Fedora)
Use yum/dnf
πͺ Installing on Windows
Go to the official download page.
Download the MSI Installer.
Run the installer (Next β Next β Finish).
Open Command Prompt or PowerShell and test:
bashCopyEditaz version
β You should see the installed version.
π Installing on macOS
If you use Homebrew:
bashCopyEditbrew update && brew install azure-cli
Then verify:
bashCopyEditaz version
π§ Installing on Linux (Ubuntu/Debian)
bashCopyEditcurl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Then verify:
bashCopyEditaz version
π 2.2 Updating Azure CLI
Azure CLI updates frequently to support new Azure services.
Update using:
Windows
Rerun the MSI installer
macOS
brew upgrade azure-cli
Linux
sudo apt-get update && sudo apt-get install azure-cli
Always try to keep your CLI updated to avoid bugs or missing features!
Check your version:
bashCopyEditaz version
You can view available updates using:
bashCopyEditaz upgrade
π 2.3 Logging in to Azure
After installation, you must authenticate.
Default login (interactive)
bashCopyEditaz login
β This opens a browser window asking for your Microsoft credentials.
Login with Device Code (for MFA or Cloud Shell)
If you canβt open a browser (example: SSH session):
az login --use-device-code
This gives you a code to enter at https://microsoft.com/devicelogin.
Service Principal Login (for Automation)
For automated scripts, you should log in with a Service Principal:
bashCopyEditaz login --service-principal -u APP_ID -p PASSWORD --tenant TENANT_ID
(We'll dive into Service Principals later in the course.)
π 2.4 Setting the Active Subscription
If you have multiple Azure subscriptions, you need to set the active one.
First, list your subscriptions:
az account list --output table
Example output:
MyCompany-Production
1234abcd-5678-efgh-9101-ijklmnopqrst
Enabled
MyCompany-Dev
8765zyxw-4321-vuts-1098-ponmlkjihgfed
Enabled
Then set your active subscription:
az account set --subscription "MyCompany-Dev"
β Now, every command you run will operate against that subscription.
π οΈ 2.5 Verifying Your CLI Environment
Double-check everything by running:
az account show
You should see:
Your current subscription
Your tenant ID
Your user ID
And finally:
az group list
If you get a valid response (even if empty), your CLI is ready!
Last updated