Introduction to Azure CLI
The Azure Command-Line Interface (CLI) is a powerful tool for managing Azure resources. It allows you to interact with Azure services from your command line, automate tasks, and deploy infrastructure efficiently. This tutorial will guide you through the initial steps of installing and using the Azure CLI.
Why use Azure CLI?
- Cross-platform: Available on Windows, macOS, and Linux.
- Automation: Easily script repetitive tasks.
- Integration: Works seamlessly with CI/CD pipelines.
- Comprehensive: Supports a wide range of Azure services.
Step 1: Installation
First, you need to install the Azure CLI on your local machine. Choose the method appropriate for your operating system.
Download and Install
Visit the official Azure CLI installation page for detailed instructions for your OS:
Verify Installation
After installation, open your terminal or command prompt and run the following command to check if the CLI is installed correctly:
az --version
You should see output similar to this (versions may vary):
azure-cli 2.37.0
...
Step 2: Login to Azure
Once installed, you need to log in to your Azure account to start managing resources.
Run the Login Command
Execute the following command in your terminal:
az login
This will open a web browser where you can sign in with your Azure credentials. If you are using a headless environment, follow the instructions to log in using a device code.
Select Your Subscription (if applicable)
If you have multiple Azure subscriptions, you might need to set the active subscription. First, list your subscriptions:
az account list --output table
Then, set your desired subscription:
az account set --subscription "Your Subscription Name or ID"
Step 3: Your First Azure CLI Command
Let's try a simple command to get information about your Azure account.
Get Account Information
Use the following command to display your current account details:
az account show --output table
This command will output details about your active subscription, tenant, user information, and more in a readable table format.
Next Steps
Congratulations! You've successfully installed and logged in with the Azure CLI. Here are some suggestions for your next steps:
- Explore resource groups:
az group --help
- Create a resource group:
az group create --name MyResourceGroup --location eastus
- List available Azure services:
az provider list --output table
- Discover more commands on the Azure CLI Command Reference.
The Azure CLI is a vast tool. Keep practicing and exploring its capabilities to maximize your Azure management efficiency.
Explore More Azure Tutorials