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-cliThen verify:
bashCopyEditaz version🐧 Installing on Linux (Ubuntu/Debian)
bashCopyEditcurl -sL https://aka.ms/InstallAzureCLIDeb | sudo bashThen 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 versionYou 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-codeThis 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 tableExample 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 showYou should see:
Your current subscription
Your tenant ID
Your user ID
And finally:
az group listIf you get a valid response (even if empty), your CLI is ready!
Last updated