您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

在 Windows 上安装 Azure CLIInstall Azure CLI on Windows

在 Windows 上,Azure CLI 是通过 MSI 安装的,因此,可以通过 Windows 命令提示符 (CMD) 或 PowerShell 访问 CLI。For Windows the Azure CLI is installed via an MSI, which gives you access to the CLI through the Windows Command Prompt (CMD) or PowerShell. 为适用于 Linux 的 Windows 子系统 (WSL) 安装时,可以安装适用于 Linux 分发版的包。When installing for Windows Subsystem for Linux (WSL), packages are available for your Linux distribution. 请参阅安装主页,获取受支持包管理器的列表,或者了解如何在 WSL 下手动进行安装。See the main install page for the list of supported package managers or how to install manually under WSL.

Azure CLI 的当前版本为 2.0.74The current version of the Azure CLI is 2.0.74. 有关最新版本的信息,请参阅发行说明For information about the latest release, see the release notes. 若要查找你已安装的版本并查看是否需要更新,请运行 az --versionTo find your installed version and see if you need to update, run az --version.

安装或更新Install or update

MSI 分发版用于在 Windows 上安装或更新 Azure CLI。The MSI distributable is used for installing or updating the Azure CLI on Windows. 在使用 MSI 安装程序之前,不需要卸载任何当前版本。You don't need to uninstall any current versions before using the MSI installer.

当安装程序询问是否可以对计算机进行更改时,请单击“是”框。When the installer asks if it can make changes to your computer, click the "Yes" box.

也可使用 PowerShell 安装 Azure CLI。You can also install the Azure CLI using PowerShell. 以管理员身份启动 PowerShell 并运行以下命令:Start PowerShell as administrator and run the following command:

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'

这将下载并安装适用于 Windows 的 Azure CLI 最新版本。This will download and install the latest version of the Azure CLI for Windows. 如果已安装一个版本,这将更新现有版本。If you already have a version installed, it will update the existing version. 安装完成后,需要重新打开 PowerShell 以使用 Azure CLI。After the installation is complete, you will need to reopen PowerShell to use the Azure CLI.

现在可以通过 Windows 命令提示符或 PowerShell 使用 az 命令运行 Azure CLI 了。You can now run the Azure CLI with the az command from either Windows Command Prompt or PowerShell. PowerShell 提供了 Windows 命令提示符所不能提供的一些 Tab 键补全功能。PowerShell offers some tab completion features not available from Windows Command Prompt. 若要登录,请运行 az login 命令。To sign in, run the az login command.

  1. 运行 login 命令。Run the login command.

    az login
    

    如果 CLI 可以打开默认浏览器,它将这样做并加载 Azure 登录页。If the CLI can open your default browser, it will do so and load an Azure sign-in page.

    否则,请在 https://aka.ms/devicelogin 处打开浏览器页,然后输入终端中显示的授权代码。Otherwise, open a browser page at https://aka.ms/devicelogin and enter the authorization code displayed in your terminal.

  2. 在浏览器中使用帐户凭据登录。Sign in with your account credentials in the browser.

若要详细了解不同的身份验证方法,请参阅使用 Azure CLI 登录To learn more about different authentication methods, see Sign in with Azure CLI.

故障排除Troubleshooting

以下是在 Windows 上安装时出现的一些常见问题。Here are some common problems seen when installing on Windows. 如果遇到的问题未在本文中列出,请在 GitHub 上提出问题If you experience a problem not covered here, file an issue on GitHub.

代理块连接Proxy blocks connection

如果由于代理阻止连接而不能下载 MSI 安装程序,请确保已正确配置代理。If you can't download the MSI installer because your proxy is blocking the connection, make sure that you have your proxy properly configured. 对于 Windows 10,这些设置是在 Settings > Network & Internet > Proxy 窗格中管理的。For Windows 10, these settings are managed in the Settings > Network & Internet > Proxy pane. 如果要了解所需的设置,或者在计算机可能是配置管理型计算机或需要高级设置的情况下,请与系统管理员联系。Contact your system administrator for the required settings, or for situations where your machine may be configuration-managed or require advanced setup.

重要

这些设置也需要能够通过 CLI(从 PowerShell 或命令提示符)访问 Azure 服务。These settings are also required to be able to access Azure services with the CLI, from both PowerShell or the Command Prompt. 在 PowerShell 中,请使用以下命令执行此操作:In PowerShell, you do this with the following command:

(New-Object System.Net.WebClient).Proxy.Credentials = `
  [System.Net.CredentialCache]::DefaultNetworkCredentials

为了获取 MSI,代理必须允许与以下地址之间的 HTTPS 连接:In order to get the MSI, your proxy needs to allow HTTPS connections to the following addresses:

  • https://aka.ms/
  • https://azurecliprod.blob.core.windows.net/

卸载Uninstall

如果你决定卸载 Azure CLI,我们会很遗憾。If you decide to uninstall the Azure CLI, we're sorry to see you go. 在卸载之前,请使用 az feedback 命令告诉我们在哪些方面需要改进或修复。Before you uninstall, use the az feedback command to let us know what could be improved or fixed. 我们的目标是消除 Azure CLI 中的 bug 并使其变得用户友好。Our goal is to make the Azure CLI bug-free and user-friendly. 如果你在发现 bug 后提出 GitHub 问题,我们将十分感激。If you found a bug, we'd appreciate it if you file a GitHub issue.

通过 Windows 中的“应用和功能”列表卸载 Azure CLI。You uninstall the Azure CLI from the Windows "Apps and Features" list. 若要卸载:To uninstall:

平台Platform 说明Instructions
Windows 10Windows 10 “开始”>“设置”>“应用”Start > Settings > Apps
Windows 8Windows 8
Windows 7Windows 7
“开始”>“控制面板”>“程序”>“卸载程序”Start > Control Panel > Programs > Uninstall a program

进入此屏幕后,请在程序搜索栏中键入 Azure CLIOnce on this screen type Azure CLI into the program search bar. 要卸载的程序列为“Microsoft CLI 2.0 for Azure”。 The program to uninstall is listed as Microsoft CLI 2.0 for Azure. 选择此应用程序,然后单击 Uninstall 按钮。Select this application, then click the Uninstall button.

后续步骤Next Steps

现在你已经安装了 Azure CLI,下面简要介绍其功能和常用命令。Now that you've installed the Azure CLI, take a short tour of its features and common commands.