您现在访问的是微软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、Fedora 19 和更高版本以及 CentOS 7 中测试。This package has been tested with RHEL 7, Fedora 19 and higher, and CentOS 7.

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.

重要

Azure CLI 的 RPM 包依赖于 python 包。The RPM package of the Azure CLI depends on the python package. 在你的系统上,这可能是早于所要求的 Python 2.7.x 的 Python 版本。On your system, this may be a Python version which predates the requirement of Python 2.7.x. 如果这对你有影响,请找到一个替代 python 包,或按照手动安装说明执行操作。If this affects you, find a replacement python package or follow the manual install instructions.

请注意,Python 2 将于 2020 年 1 月 1 日停用并且不会再收到更新。Be aware that Python 2 is being end-of-lifed on January 1, 2020, and will no longer receive updates. 出于此原因,请升级到 Python 3(如果可能)。For this reason, upgrade to Python 3 when possible. Azure CLI 与 Python 3.6 及更高版本兼容。The Azure CLI is compatible with Python 3.6 and higher.

安装Install

  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
    baseurl=https://packages.microsoft.com/yumrepos/azure-cli
    enabled=1
    gpgcheck=1
    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.

故障排除Troubleshooting

下面是使用 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.

代理块连接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. 请确保以下行显示在 /etc/yum.conf[main] 部分下:Make sure that the following lines appear under the [main] section of /etc/yum.conf:

[main]
# ...
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.

更新Update

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

sudo yum update azure-cli

卸载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.

  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.