使用 zypper 安裝 Azure CLIInstall Azure CLI with zypper

對於 Linux zypper 所隨附的散發套件 (如 openSUSE 或 SLES),有適用於 Azure CLI 的套件。For Linux distributions with zypper, such as openSUSE or SLES, there's a package available for the Azure CLI. 此套件已在 openSUSE 42.2 和 SLES 12 SP 2 上經過測試。This package has been tested with openSUSE 42.2 and SLES 12 SP 2.

目前的 CLI 版本為 2.0.59The current version of the CLI is 2.0.59. 如需最新版本的相關資訊,請參閱版本資訊For information about the latest release, see the release notes. 若要尋找您系統上執行的版本,以查看是否需要更新,請執行 az --versionTo find the version running on your system to 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.

InstallInstall

  1. 安裝 curlInstall curl:

    sudo zypper install -y curl
    
  2. 匯入 Microsoft 存放庫金鑰:Import the Microsoft repository key:

    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
  3. 建立本機 azure-cli 存放庫資訊:Create local azure-cli repository information:

    sudo zypper addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli
    
  4. 更新 zypper 套件索引並安裝:Update the zypper package index and install:

    sudo zypper install --from azure-cli -y azure-cli
    

然後您可以使用 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 可以開啟預設瀏覽器,它會執行這項操作,並載入登入頁面。If the CLI can open your default browser, it will do so and load a sign-in page.

    否則,您需要開啟瀏覽器頁面,並遵循命令列中的指示,在瀏覽器中瀏覽至 https://aka.ms/devicelogin 之後,輸入授權碼。Otherwise, you need to open a browser page and follow the instructions on the command line to enter an authorization code after navigating to https://aka.ms/devicelogin in your browser.

  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

以下是一些使用 zypper 安裝時常見的問題。Here are some common problems seen when installing with zypper. 如果您遇到此處未涵蓋的問題,在 github 上提出問題If you experience a problem not covered here, file an issue on github.

無法在適用於 Linux 的 Windows 子系統上安裝 CLI,或無法在適用於 Linux 的 Windows 子系統上執行 CLICLI 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

您可以使用 zypper update 命令更新套件。You can update the package with the zypper update command.

sudo zypper refresh
sudo zypper 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 既沒有錯誤又易於使用。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 zypper remove -y azure-cli
    
  2. 如果您不打算重新安裝 CLI,請移除存放庫資訊。If you don't plan to reinstall the CLI, remove the repository information.

    sudo zypper removerepo azure-cli
    
  3. 如果您移除存放庫資訊,也會移除 Microsoft GPG 簽章金鑰。If you removed the repository information, also remove the Microsoft GPG signature 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.