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

使用 yum 安装 Azure CLIInstall Azure CLI with yum

对于附带 yum 的 Linux 分发版(例如 RHEL、Fedora 或 CentOS),可以安装适用于 Azure CLI 的包。For Linux distributions with yum such as RHEL, Fedora, or CentOS, there's a package for the Azure CLI. 此包已在 RHEL 7.7、RHEL 8、Fedora 24 和更高版本、CentOS 7 和 CentOS 8 中测试。This package has been tested with RHEL 7.7, RHEL 8, Fedora 24 and higher, CentOS 7 and CentOS 8.

当前的 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.


Azure CLI 的 RPM 包依赖于 python3 包。The RPM package of the Azure CLI depends on the python3 package. 在你的系统上,这可能是早于所要求的 Python 3.6.x 的 Python 版本。On your system, this may be a Python version which predates the requirement of Python 3.6.x. 如果这对你有影响,请找一个替代 python3 包。If this affects you, find a replacement python3 package.

请注意,Python 2 已于 2020 年 1 月 1 日停用,再也不会收到更新。Be aware that Python 2 has reached the end of life on January 1, 2020, and will no longer receive updates. 自版本 2.1.0 发布以来,Azure CLI 已放弃对 Python 2.7 的支持。Azure CLI has dropped support for Python 2.7 since version 2.1.0. 新版本不再保证在 Python 2.7 环境中正常运行。New versions no longer guarantee to run with Python 2.7 correctly.


  1. 导入 Microsoft 存储库密钥。Import the Microsoft repository key.

    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
  2. 创建本地 azure-cli 存储库信息。Create local azure-cli repository information.

    sudo sh -c 'echo -e "[azure-cli]
    name=Azure CLI
    gpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
  3. 使用 yum install 命令安装。Install with the yum install command.

    sudo yum install azure-cli

使用 az 命令运行 Azure CLI。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.


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

安装在 RHEL 7.6 或不带 Python 3 的其他系统上Install on RHEL 7.6 or other systems without Python 3

如果可以,请将系统升级到带有对 python3 包的官方支持的版本。If you can, please upgrade your system to a version with official support for python3 package. 否则,需要首先安装 python3 包(从源代码生成,或者通过某个其他存储库进行安装)。Otherwise, you need to first install a python3 package, either build from source or install through some additional repo. 然后即可下载包,并在没有依赖项的情况下安装它。Then you can download the package and install it without dependency.

$ sudo yum install yum-utils
$ sudo yumdownloader azure-cli
$ sudo rpm -ivh --nodeps azure-cli-*.rpm

如果已安装 python3,但在尝试运行 cli 时仍收到错误 python3: command not found,则需要将其添加到你的路径。If you have setup python3 but are still getting an error python3: command not found when trying to run the cli, you need to add it to your path.

$ scl enable rh-python36 bash

代理阻止连接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.

你可能还想要显式配置 yum 以便在所有情况下都使用此代理。You may also want to explicitly configure yum to use this proxy at all times. 请确保以下行显示在 [main]/etc/yum.conf 部分下:Make sure that the following lines appear under the [main] section of /etc/yum.conf:

# ...
proxy=http://[proxy]:[port] # If your proxy requires https, change http->https
proxy_username=[username] # Only required for basic auth
proxy_password=[password] # Only required for basic auth

为了获取 Microsoft 签名密钥并从我们的存储库中获取包,代理必须允许与以下地址之间的 HTTPS 连接:In order to get the Microsoft signing key and get the package from our repository, your proxy needs to allow HTTPS connections to the following address:

  • https://packages.microsoft.com

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.


使用 yum update 命令更新 Azure CLI。Update the Azure CLI with the yum update command.

sudo yum update 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.

  1. 从系统中删除包。Remove the package from your system.

    sudo yum remove azure-cli
  2. 如果不打算重新安装 CLI,请删除存储库信息。If you don't plan to reinstall the CLI, remove the repository information.

    sudo rm /etc/yum.repos.d/azure-cli.repo
  3. 如果不使用任何其他 Microsoft 包,请删除签名密钥。If you don't use any other Microsoft packages, remove the signing key.

    MSFT_KEY=`rpm -qa gpg-pubkey /* --qf "%{version}-%{release} %{summary}\n" | grep Microsoft | awk '{print $1}'`
    sudo rpm -e --allmatches gpg-pubkey-$MSFT_KEY

后续步骤Next Steps

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