全部產品
Search
文件中心

Alibaba Cloud CLI:更新阿里雲CLI

更新時間:Jan 28, 2026

本文為您介紹更新阿里雲CLI的注意事項及操作步驟。

注意事項

  • 為避免版本混淆及潛在的相容性問題,建議您始終使用與初始安裝方法相匹配的更新渠道進行操作。例如:

    • 通過Homebrew安裝的阿里雲CLI應繼續使用Homebrew進行更新,不推薦使用安裝包或指令碼方式進行升級。

    • 在Linux/macOS上使用自訂安裝目錄安裝的阿里雲CLI,推薦使用TGZ安裝包手動更新以確保正確覆蓋舊版本檔案。

  • 若您在安裝阿里雲CLI時使用了自訂安裝路徑,請在更新版本時指定相同路徑,以確保安裝路徑的一致性。

  • 若您更新時存在以下情況,建議您完全卸載阿里雲CLI之後,再根據需求重新執行安裝操作。

    • 不確定初始安裝方式或安裝目錄。

    • 需要更換為不相容的安裝方式。例如:從指令碼安裝切換為使用Homebrew安裝。

    • 需要修改安裝目錄。

更新步驟

說明

操作步驟中<script_path><install_path>均為樣本值,執行命令前需替換為實際的指令檔路徑及阿里雲CLI安裝路徑。

Linux

通過Bash指令碼更新

執行以下命令,安裝最新版本的阿里雲CLI。

/bin/bash -c "$(curl -fsSL https://aliyuncli.alicdn.com/install.sh)"

通過TGZ安裝封裝更新

  1. 根據系統架構下載安裝包。

    說明

    您可以執行uname -m命令查看Linux系統架構。如果終端輸出arm64aarch64,表示您的系統架構為ARM64。輸出其他資訊則表示您的系統架構為AMD64。

    • 執行以下命令,下載適用於Linux AMD64系統的最新版本安裝包。

      curl https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz -o aliyun-cli-linux-latest.tgz
    • 執行以下命令,下載適用於Linux ARM64系統的最新版本安裝包。

      curl https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-arm64.tgz -o aliyun-cli-linux-latest.tgz
  2. 解壓安裝包到安裝目錄,覆蓋舊版本檔案。

    tar xzvf aliyun-cli-latest.tgz -C <install_path>

macOS

通過PKG安裝封裝更新

  1. 在瀏覽器中訪問下載連結https://aliyuncli.alicdn.com/aliyun-cli-latest.pkg,下載適用於macOS系統的最新版本PKG安裝包。

  2. 雙擊下載好的安裝包,按照說明指引進行操作即可完成更新。

通過Homebrew更新

執行以下命令,使用Homebrew更新阿里雲CLI。

brew update && brew upgrade aliyun-cli && brew cleanup aliyun-cli

通過Bash指令碼更新

執行以下命令,安裝最新版本的阿里雲CLI。

/bin/bash -c "$(curl -fsSL https://aliyuncli.alicdn.com/install.sh)"

通過TGZ安裝封裝更新

  1. 執行以下命令,下載適用於macOS系統的最新版本安裝包。

    curl https://aliyuncli.alicdn.com/aliyun-cli-macosx-latest-universal.tgz -o aliyun-cli-macosx-latest-universal.tgz
  2. 解壓安裝包到安裝目錄,覆蓋舊版本檔案。

    tar xzvf aliyun-cli-macosx-latest-universal.tgz -C <install_path>

Windows

通過ZIP安裝封裝更新

  1. 在瀏覽器中訪問下載連結https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip,下載適用於Windows系統的最新版本安裝包。

  2. 將安裝包中的可執行檔aliyun.exe解壓至阿里雲CLI的安裝目錄,覆蓋安裝目錄中的舊版本檔案以完成更新。

    說明

    該檔案需要通過命令列終端運行,雙擊檔案無法正常工作。

通過PowerShell指令碼更新

  1. 建立指令檔Install-CLI-Windows.ps1,並將下列代碼儲存至檔案中。若您已有此指令檔,可跳過建立步驟。

    指令碼樣本

    # Install-CLI-Windows.ps1
    # Purpose: Install Alibaba Cloud CLI on Windows AMD64 systems.
    # Supports custom version and install directory. Only modifies User-level and Process-level PATH.
    
    [CmdletBinding()]
    param (
        [string]$Version = "latest",
        [string]$InstallDir = "$env:LOCALAPPDATA",
        [switch]$Help
    )
    
    function Show-Usage {
        Write-Output @"
    
          Alibaba Cloud Command Line Interface Installer
    
        -Help                 Display this help and exit
    
        -Version VERSION      Custom CLI version. Default is 'latest'
    
        -InstallDir PATH      Custom installation directory. Default is:
                              $InstallDir\AliyunCLI
    
    "@
    }
    
    function Write-ErrorExit {
        param([string]$Message)
        Write-Error $Message
        exit 1
    }
    
    if ($PSBoundParameters['Help']) {
        Show-Usage
        exit 0
    }
    
    Write-Output @"
    ..............888888888888888888888 ........=8888888888888888888D=..............
    ...........88888888888888888888888 ..........D8888888888888888888888I...........
    .........,8888888888888ZI: ...........................=Z88D8888888888D..........
    .........+88888888 ..........................................88888888D..........
    .........+88888888 .......Welcome to use Alibaba Cloud.......O8888888D..........
    .........+88888888 ............. ************* ..............O8888888D..........
    .........+88888888 .... Command Line Interface(Reloaded) ....O8888888D..........
    .........+88888888...........................................88888888D..........
    ..........D888888888888DO+. ..........................?ND888888888888D..........
    ...........O8888888888888888888888...........D8888888888888888888888=...........
    ............ .:D8888888888888888888.........78888888888888888888O ..............
    "@
    
    $OSArchitecture = (Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture
    
    $ProcessorArchitecture = [int](Get-WmiObject -Class Win32_Processor).Architecture
    
    if (-not ($OSArchitecture -match "64") -or $ProcessorArchitecture -ne 9) {
        Write-ErrorExit "Alibaba Cloud CLI only supports Windows AMD64 systems. Please run on a compatible system."
    }
    
    $DownloadUrl = "https://aliyuncli.alicdn.com/aliyun-cli-windows-$Version-amd64.zip"
    
    $tempPath = $env:TEMP
    $randomName = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 8)
    $DownloadDir = Join-Path -Path $tempPath -ChildPath $randomName
    New-Item -ItemType Directory -Path $DownloadDir | Out-Null
    
    try {
        $InstallDir = Join-Path $InstallDir "AliyunCLI"
        if (-not (Test-Path $InstallDir)) {
            New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
        }
    
        $ZipPath = Join-Path $DownloadDir "aliyun-cli.zip"
        Start-BitsTransfer -Source $DownloadUrl -Destination $ZipPath
    
        Expand-Archive -Path $ZipPath -DestinationPath $DownloadDir -Force
    
        Move-Item -Path "$DownloadDir\aliyun.exe" -Destination "$InstallDir\" -Force
    
        $Key = 'HKCU:\Environment'
        $CurrentPath = (Get-ItemProperty -Path $Key -Name PATH).PATH
    
        if ([string]::IsNullOrEmpty($CurrentPath)) {
            $NewPath = $InstallDir
        } else {
            if ($CurrentPath -notlike "*$InstallDir*") {
                $NewPath = "$CurrentPath;$InstallDir"
            } else {
                $NewPath = $CurrentPath
            }
        }
    
        if ($NewPath -ne $CurrentPath) {
            Set-ItemProperty -Path $Key -Name PATH -Value $NewPath
            $env:PATH += ";$InstallDir"
        }
    } catch {
        Write-ErrorExit "Failed to install Alibaba Cloud CLI: $_"
    } finally {
        Remove-Item -Path $DownloadDir -Recurse -Force | Out-Null
    }
  2. 執行以下命令,運行指令檔以更新阿里雲CLI。

    powershell.exe -ExecutionPolicy Bypass -File <script_path> [-InstallDir <install_path>]