安装与设置指南 章节导航: 课程主页:AZD 初学者指南 当前章节:第1章 - 基础与快速入门 ⬅️ 上一节:AZD 基础 ➡️ 下一节:你的第一个项目 下一章:第2章:AI优先开发 简介 本指南将详细介绍如何在您的系统上安装和配置 Azure Developer CLI (azd)。您将学习适用于不同操作系统的多种安装方法、身份验证设置以及初始配置,以便为 Azure 部署准备开发环境。
章节导航:
本指南将详细介绍如何在您的系统上安装和配置 Azure Developer CLI (azd)。您将学习适用于不同操作系统的多种安装方法、身份验证设置以及初始配置,以便为 Azure 部署准备开发环境。
完成本课程后,您将能够:
完成本课程后,您将能够:
azd auth login 进行 Azure 身份验证本指南将帮助您在任何操作系统或开发环境中安装和配置 Azure Developer CLI。
在安装 azd 之前,请确保您已具备:
# Run as Administrator or with elevated privileges powershell -ex AllSigned -c "Invoke-RestMethod 'https://aka.ms/install-azd.ps1' | Invoke-Expression"
winget install Microsoft.Azd
choco install azd
C:\Program Files\azd\brew tap azure/azd brew install azd
curl -fsSL https://aka.ms/install-azd.sh | bash
# Download and install curl -fsSL https://aka.ms/install-azd.sh | bash -s -- --base-url https://github.com/Azure/azure-dev/releases/latest/download --verbose
curl -fsSL https://aka.ms/install-azd.sh | bash
Ubuntu/Debian:
# Add Microsoft package repository curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash # Install azd sudo apt-get update sudo apt-get install azd
RHEL/CentOS/Fedora:
# Add Microsoft package repository sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo dnf config-manager --add-repo https://packages.microsoft.com/yumrepos/azure-cli sudo dnf install azd
azd 已预装在 GitHub Codespaces 中。只需创建一个 codespace 即可立即使用 azd。
# Run azd in a container docker run --rm -it -v $(pwd):/workspace mcr.microsoft.com/azure-dev-cli-tools:latest # Create an alias for easier use alias azd='docker run --rm -it -v $(pwd):/workspace mcr.microsoft.com/azure-dev-cli-tools:latest azd'
安装完成后,验证 azd 是否正常工作:
# Check version azd version # View help azd --help # List available templates azd template list
预期输出:
azd version 1.5.0 (commit abc123)
✅ 安装成功检查清单:
azd version 显示版本号且无错误azd --help 显示命令文档azd template list 显示可用模板az account show 显示您的 Azure 订阅azd init如果所有检查通过,您可以继续前往 你的第一个项目!
# Install Azure CLI if not already installed # Windows: winget install Microsoft.AzureCLI # macOS: brew install azure-cli # Linux: curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash # Login to Azure az login # Verify authentication az account show
如果您使用无头系统或浏览器有问题:
az login --use-device-code
适用于自动化环境:
az login --service-principal \ --username <client-id> \ --password <client-secret> \ --tenant <tenant-id>
# Set default subscription azd config set defaults.subscription <subscription-id> # Set default location azd config set defaults.location eastus2 # View all configuration azd config list
将以下内容添加到您的 shell 配置文件(.bashrc、.zshrc、.profile):
# Azure configuration export AZURE_SUBSCRIPTION_ID="your-subscription-id" export AZURE_LOCATION="eastus2" # azd configuration export AZD_ALPHA_ENABLE_APPSERVICE_REMOTE_DEBUGGING=true export AZD_DEBUG=true # Enable debug logging
安装 Azure Developer CLI 扩展:
功能:
创建 .devcontainer/devcontainer.json:
{ "name": "Azure Developer CLI", "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "features": { "ghcr.io/azure/azure-dev/azd:latest": {} }, "postCreateCommand": "azd version" }
# Run PowerShell as Administrator Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
手动将 azd 添加到 PATH:
Windows:
setx PATH "%PATH%;C:\Program Files\azd\"
macOS/Linux:
echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bashrc source ~/.bashrc
# Configure proxy azd config set http.proxy http://proxy:8080 azd config set https.proxy https://proxy:8080 # Skip SSL verification (not recommended for production) azd config set http.insecure true
# Remove old installations # Windows: winget uninstall Microsoft.Azd # macOS: brew uninstall azd # Linux: sudo apt remove azd # Clean configuration rm -rf ~/.azd
# Enable debug logging export AZD_DEBUG=true azd <command> --debug # View detailed logs azd logs # Check system info azd info
azd 会在有更新时通知您:
azd version --check-for-updates
Windows (winget):
winget upgrade Microsoft.Azd
macOS (Homebrew):
brew upgrade azd
Linux:
curl -fsSL https://aka.ms/install-azd.sh | bash
Azure CLI (az):用于管理单个 Azure 资源的低级工具
az webapp create,az storage account createAzure Developer CLI (azd):用于完整应用程序部署的高级工具
azd up 部署包含所有资源的整个应用程序两者都需要:azd 使用 az CLI 进行身份验证
可以!您可以:
详见 配置指南。
支持,配置云环境:
# Azure Government az cloud set --name AzureUSGovernment az login # Azure China az cloud set --name AzureChinaCloud az login
当然可以!azd 专为自动化设计:
详见 部署指南 了解 CI/CD 模式。
azd 本身是完全免费且开源的。您只需支付:
使用 azd provision --preview 在部署前估算成本。
azd template list 浏览可用模板如果您遇到问题:
章节导航:
✅ 安装完成! 继续前往 你的第一个项目,开始使用 azd 构建项目吧。
免责声明:
本文档使用AI翻译服务Co-op Translator进行翻译。尽管我们努力确保翻译的准确性,但请注意,自动翻译可能包含错误或不准确之处。原始语言的文档应被视为权威来源。对于重要信息,建议使用专业人工翻译。我们对因使用此翻译而产生的任何误解或误读不承担责任。