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

在 macOS 上安装 Azure CLIInstall Azure CLI on macOS

对于 macOS 平台,可以通过 homebrew 包管理器安装 Azure CLI。For the macOS platform, you can install the Azure CLI with homebrew package manager. 使用 Homebrew 可以轻松保持 CLI 的最新安装状态。Homebrew makes it easy to keep your installation of the CLI update to date. 该 CLI 包已在 macOS 10.9 和更高版本中测试。The CLI package has been tested on macOS versions 10.9 and later.

当前的 Azure CLI 版本为 2.6.0。The current version of the Azure CLI is 2.6.0. 有关最新版本的信息,请参阅发行说明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.

使用 Homebrew 安装Install with Homebrew

Homebrew 是管理 CLI 安装的最容易的方法。Homebrew is the easiest way to manage your CLI install. 它可以方便地进行安装、更新和卸载。It provides convenient ways to install, update, and uninstall. 如果系统中没有可用的 Homebrew,请先安装 Homebrew,然后继续。If you don't have homebrew available on your system, install homebrew before continuing.

安装 CLI 时,可以先更新 brew 存储库信息,然后运行 install 命令:You can install the CLI by updating your brew repository information, and then running the install command:

brew update && brew install azure-cli


Azure CLI 依赖于 Homebrew python3 包,并将安装它。The Azure CLI has a dependency on the Homebrew python3 package, and will install it. Azure CLI 保证可与 Homebrew 上发布的最新版本的 python3 兼容。The Azure CLI is guaranteed to be compatible with the latest version of python3 published on Homebrew.

然后即可使用 az 命令来运行 Azure CLI。You can then run the Azure CLI with the az command. 若要登录,请使用 az login 命令。To sign in, use 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.


如果在通过 Homebrew 安装 CLI 时遇到问题,会显示以下常见错误。If you encounter a problem when installing the CLI through Homebrew, here are some common errors. 如果遇到的问题未在本文中列出,请在 github 上提出问题If you experience a problem not covered here, file an issue on github.

无法完成Completion is not working

Azure CLI 的 Homebrew 公式将在 Homebrew 托管的完成目录中安装名为 az 的完成文件(默认位置为 /usr/local/etc/bash_completion.d/)。The Homebrew formula of Azure CLI installs a completion file named az in the Homebrew-managed completions directory (default location is /usr/local/etc/bash_completion.d/). 若要启用完成功能,请按此处的 Homebrew 说明操作。To enable completion, please follow Homebrew's instructions here.

找不到 Python 或安装的包Unable to find Python or installed packages

在执行 Homebrew 安装期间,可能会出现次要版本不匹配或其他问题。There may be a minor version mismatch or other issue during homebrew installation. CLI 不会使用 Python 虚拟环境,因此,它只能查找已安装的 Python 版本。The CLI doesn't use a Python virtual environment, so it relies on finding the installed Python version. 可行的解决方法之一是从 Homebrew 安装并重新链接 python3 依赖项。A possible fix is to install and relink the python3 dependency from Homebrew.

brew update && brew install python3 && brew upgrade python3
brew link --overwrite python3

已安装 CLI 安装 1.xCLI version 1.x is installed

如果安装了过时的版本,则陈旧的 Homebrew 缓存可能导致此问题。If an out-of-date version was installed, it could be because of a stale homebrew cache. 请遵照更新说明操作。Follow the update instructions.

代理阻止连接Proxy blocks connection

你可能无法从 Homebrew 获取资源,除非已将其正确配置为使用你的代理。You may be unable to get resources from Homebrew unless you have correctly configured it to use your proxy. 请遵循 Homebrew 代理配置说明Follow the Homebrew proxy configuration instructions.


如果你位于代理后面,则必须设置 HTTP_PROXYHTTPS_PROXY 以通过 CLI 连接到 Azure 服务。If you are behind a proxy, HTTP_PROXY and HTTPS_PROXY must be set to connect to Azure services with the CLI. 如果不使用基本身份验证,建议将这些变量导出到 .bashrc 文件中。If you are not using basic auth, it's recommended to export these variables in your .bashrc file. 请始终遵循企业的安全策略和系统管理员的要求。Always follow your business' security policies and the requirements of your system administrator.

为了从 Homebrew 获取 Bottle 资源,代理必须允许与以下地址之间的 HTTPS 连接:In order to get the bottle resources from Homebrew, your proxy needs to allow HTTPS connections to the following addresses:

  • https://formulae.brew.sh
  • https://homebrew.bintray.com


CLI 定期使用 Bug 修复、改进、新功能和预览版功能进行更新。The CLI is regularly updated with bug fixes, improvements, new features, and preview functionality. 新版本大约两周发布一次。A new release is available roughly every two weeks. 更新本地存储库信息,然后升级 azure-cli 包。Update your local repository information and then upgrade the azure-cli package.

brew update && brew upgrade azure-cli


如果你决定卸载 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.

使用 Homebrew 卸载 azure-cli 包。Use homebrew to uninstall the azure-cli package.

brew uninstall azure-cli

其他安装方法Other installation methods

如果不能使用 homebrew 在你的环境中安装 Azure CLI,可以使用适用于 Linux 的手册说明。If you can't use homebrew to install the Azure CLI in your environment, it's possible to use the manual instructions for Linux. 请注意,此过程未正式保持与 macOS 兼容。Note that this process is not officially maintained to be compatible with macOS. 始终建议使用诸如 Homebrew 之类的包管理器。Using a package manager such as Homebrew is always recommended. 仅当没有其他选项可用时才使用手动安装方法。Only use the manual installation method if you have no other option available.

有关手动安装说明,请参阅在 Linux 上手动安装 Azure CLIFor the manual installation instructions, see Install Azure CLI on Linux manually.

后续步骤Next Steps

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