如何成功安装 Azure CLI

如何成功安装 Azure CLI

我在安装 Azure CLI 时遇到问题。我尝试了三种方法,但都失败了。

前两个来自在 Windows 上安装 Azure CLI, 我试过了

  • 使用 PowerShell 安装 Azure CLI,并
  • 自行下载并安装最新版本的 Azure CLI .msi 文件。
  • 我也尝试过删除它并使用.msi 文件重新安装。

但在所有情况下,如果我输入az,我会得到

az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program.

然后我尝试在 Linux 上安装 Azure CLI作为最后的手段,但它也失败了:

+ echo 'deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ bullseye main'
+ apt-get update
Hit:1 http://security.debian.org/debian-security bullseye-security InRelease
Hit:2 http://deb.debian.org/debian bullseye InRelease                                                                
Hit:3 http://ftp.debian.org/debian bullseye-backports InRelease                                                      
Hit:4 http://deb.debian.org/debian bullseye-updates InRelease                                                        
Hit:5 http://ppa.launchpad.net/suntong001/ppa/ubuntu focal InRelease                               
Get:6 https://packages.microsoft.com/repos/azure-cli bullseye InRelease [10.4 kB]
Err:6 https://packages.microsoft.com/repos/azure-cli bullseye InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
Reading package lists... Done
W: http://security.debian.org/debian-security/dists/bullseye-security/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/microsoft.gpg are ignored as the file is not readable by user '_apt' executing apt-key.
W: http://deb.debian.org/debian/dists/bullseye/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/microsoft.gpg are ignored as the file is not readable by user '_apt' executing apt-key.
W: http://ftp.debian.org/debian/dists/bullseye-backports/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/microsoft.gpg are ignored as the file is not readable by user '_apt' executing apt-key.
W: http://deb.debian.org/debian/dists/bullseye-updates/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/microsoft.gpg are ignored as the file is not readable by user '_apt' executing apt-key.
W: http://ppa.launchpad.net/suntong001/ppa/ubuntu/dists/focal/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/microsoft.gpg are ignored as the file is not readable by user '_apt' executing apt-key.
W: https://packages.microsoft.com/repos/azure-cli/dists/bullseye/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/microsoft.gpg are ignored as the file is not readable by user '_apt' executing apt-key.
W: GPG error: https://packages.microsoft.com/repos/azure-cli bullseye InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
E: The repository 'https://packages.microsoft.com/repos/azure-cli bullseye InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

答案1

在 Windows 上,你可以找到 Azure CLI命令这里:
C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin

该路径可以在环境变量中找到Path在此处输入图片描述

电源外壳: $Env:Path

C:\Program 文件(x86)\Microsoft SDKs\Azure\CLI2\wbin;

如果使用 msi 文件安装 Azure CLI,它将安装应用程序并将位置添加到Path变量。

如果打开了 PowerShell,则Path不会在后台自动刷新。您必须关闭 PowerShell 并打开新会话。通常,Path会加载更新。此行为也适用于更多应用程序。

因此,重新启动机器可能是有意义的(或者如果你想要安全起见)。

顺便说一句:也可以在 Windows 11 中刷新环境变量(无需重启)例如 Chocolatey

相关内容