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

在 Linux 上手动安装 Azure CLIInstall Azure CLI on Linux manually

如果没有适用于你的分发版的 Azure CLI 包,请运行一个脚本来手动安装 CLI。If there's no package for the Azure CLI for you your distribution, install the CLI manually by running a script.

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


强烈建议使用包管理器安装 CLI。It's strongly recommend to install the CLI with a package manager. 使用包管理器可确保始终获得最新更新,并保证 CLI 组件的稳定性。A package manager makes sure you always get the latest updates, and guarantees the stability of CLI components. 在手动安装之前,请检查发行版是否有对应的包。Check and see if there is a package for your distribution before installing manually.


CLI 需要以下软件:The CLI requires the following software:


该 CLI 也与 Python 2.7.x 兼容,后者将于 2020 年 1 月 1 日停用。The CLI is also compatible with Python 2.7.x, which is being end-of-lifed on January 1, 2020. 出于此原因,我们建议安装 Python 3 以运行该 CLI。For this reason we recommend that you install Python 3 to run the CLI.

安装或更新Install or update

安装和更新 CLI 都需要重新运行安装脚本。Both installing and updating the CLI requires re-running the install script. 运行 curl 来安装 CLI。Install the CLI by running curl.

curl -L https://aka.ms/InstallAzureCli | bash

也可以下载并在本地运行该脚本。The script can also be downloaded and run locally. 可能需要重启 shell 才能使更改生效。You may have to restart your shell in order for changes to take effect.

然后即可使用 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.


下面是手动安装过程中可能出现的一些常见问题。Here are some common problems seen during a manual installation. 如果遇到的问题未在本文中列出,请在 GitHub 上提出问题If you experience a problem not covered here, file an issue on GitHub.

curl“对象已移动”错误curl "Object Moved" error

如果从有关 -L 参数的 curl 收到错误,或者收到包含“对象已移动”的错误消息,请尝试使用完整 URL 而不是 aka.ms 重定向:If you get an error from curl related to the -L parameter, or an error message including the text "Object Moved", try using the full URL instead of the aka.ms redirect:

curl https://azurecliprod.blob.core.windows.net/install | bash

找不到 az 命令az command not found

如果在安装后以及在使用 bashzsh 时无法运行该命令,请清除 shell 的命令哈希缓存。If you can't run the command after installation and using bash or zsh, clear your shell's command hash cache. 运行Run

hash -r

并查看问题是否得到解决。and check if the problem is resolved.

如果在安装后没有重启 shell,也可能出现此错误。The issue can also occur if you didn't restart your shell after installation. 确保 az 命令的位置在 $PATH 中。Make sure that the location of the az command is in your $PATH. az 命令的位置为The location of the az command is

<install path>/bin

代理块连接Proxy blocks connection

如果由于代理而无法连接到外部资源,请确保已在 shell 中正确设置了 HTTP_PROXYHTTPS_PROXY 变量。If you're unable to connect to an external resource due to a proxy, make sure that you've correctly set the HTTP_PROXY and HTTPS_PROXY variables in your shell. 你需要与系统管理员联系以了解要对这些代理使用哪些主机和端口。You will need to contact your system administrator to know what host(s) and port(s) to use for these proxies.

许多 Linux 程序(包括那些在安装过程中使用的程序)也会采用这些值。These values are respected by many Linux programs, including those which are used in the install process. 若要设置这些值,请执行以下操作:To set these values:

# No auth
export HTTP_PROXY=http://[proxy]:[port]
export HTTPS_PROXY=https://[proxy]:[port]

# Basic auth
export HTTP_PROXY=http://[username]:[password]@[proxy]:[port]
export HTTPS_PROXY=https://[username]:[password]@[proxy]:[port]


如果你位于代理后面,则必须设置这些 shell 变量以通过 CLI 连接到 Azure 服务。If you are behind a proxy, these shell variables 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.

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

  • https://aka.ms/
  • https://azurecliprod.blob.core.windows.net/
  • https://pypi.python.org
  • 分发版的包管理器(如果有)用于核心包的终结点Endpoints used by your distribution's package manager (if any) for core packages

CLI 未能在适用于 Linux 的 Windows 子系统上安装或运行CLI fails to install or run on Windows Subsystem for Linux

由于适用于 Linux 的 Windows 子系统 (WSL) 是基于 Windows 平台的一个系统调用转换层,因此,在尝试安装或运行 Azure CLI 时可能会发生错误。Since Windows Subsystem for Linux (WSL) is a system call translation layer on top of the Windows platform, you might experience an error when trying to install or run the Azure CLI. CLI 依赖于在 WSL 中可能具有 bug 的某些功能。The CLI relies on some features that may have a bug in WSL. 如果无论你以何方式安装 CLI 都会发生错误,则很可能是因为 WSL 有问题而不是 CLI 安装过程有问题。If you experience an error no matter how you install the CLI, there's a good chance it's an issue with WSL and not with the CLI install process.

若要对 WSL 安装进行故障排除并尽可能解决问题,请执行以下操作:To troubleshoot your WSL installation and possibly resolve issues:

  • 如果可以,在 Linux 计算机或 VM 上运行相同的安装过程来看看它是否会成功。If you can, run an identical install process on a Linux machine or VM to see if it succeeds. 如果成功,则几乎可以肯定问题与 WSL 有关。If it does, your issue is almost certainly related to WSL. 若要启动 Azure 中的 Linux VM,请参阅在 Azure 门户中创建 Linux VM 文档。To start a Linux VM in Azure, see the create a Linux VM in the Azure Portal documentation.
  • 确保运行的是最新版本的 WSL。Make sure that you're running the latest version of WSL. 若要获取最新版本,请更新 Windows 10 安装To get the latest version, update your Windows 10 installation.
  • 检查 WSL 是否存在可能会解决你的问题的待解决问题Check for any open issues with WSL which might address your problem. 那里通常会提供有关如何解决该问题的建议,或者提供有关将修复该问题的发行版的信息。Often there will be suggestions on how to work around the problem, or information about a release where the issue will be fixed.
  • 如果没有与你的问题对应的现有问题,请提交一个新的 WSL 问题并确保提供尽可能多的信息。If there are no existing issues for your problem, file a new issue with WSL and make sure that you include as much information as possible.

如果在 WSL 上安装或运行时继续出现问题,请考虑安装适用于 Windows 的 CLIIf you continue to have issues installing or running on WSL, consider installing the CLI for Windows.


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

可以通过直接从安装时所选的位置删除文件来卸载 CLI。Uninstall the CLI by directly deleting the files from the location chosen at the time of installation. 默认安装位置是 $HOMEThe default install location is $HOME.

  1. 删除安装的 CLI 文件。Remove the installed CLI files.

    rm -r <install location>/lib/azure-cli
    rm <install location>/bin/az
  2. 修改 $HOME/.bash_profile 文件,删除以下行:Modify your $HOME/.bash_profile file to remove the following line:

    <install location>/lib/azure-cli/az.completion
  3. 如果使用 bashzsh,请重新加载 shell 的命令缓存。If using bash or zsh, reload your shell's command cache.

    hash -r

后续步骤Next Steps

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