全部產品
Search
文件中心

Alibaba Cloud CLI:在Windows系統中安裝阿里雲CLI

更新時間:May 23, 2025

本文為您介紹在Windows系統中安裝阿里雲CLI的操作步驟。

安裝步驟

重要

阿里雲CLI當前僅適用於Windows AMD64架構系統,暫不支援32位及其他非AMD64架構(如ARM64)的Windows系統安裝阿里雲CLI。

在Windows系統中,您可以通過以下方式安裝阿里雲CLI:

通過圖形化使用者介面手動安裝

  1. 下載安裝包

  2. 將安裝包中的可執行檔aliyun.exe解壓至您期望的目錄,該目錄將作為阿里雲CLI的安裝目錄。

    說明

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

  3. 按下Windows鍵+S鍵開啟搜尋介面,輸入搜尋關鍵詞“環境變數”。

  4. 在搜尋結果中單擊編輯賬戶的環境變數,開啟環境變數設定介面。

  5. 使用者變數中選擇鍵為Path的環境變數,單擊編輯

  6. 在編輯介面中單擊建立,輸入阿里雲CLI安裝目錄路徑。樣本目錄:C:\ExampleDir(請替換為實際安裝目錄的路徑)。

    image

  7. 在所有開啟的對話方塊中依次單擊確定以儲存更改。

  8. 重新啟動終端會話以使更改生效。

通過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。

    說明

    樣本指令碼路徑為C:\Example\Install-CLI-Windows.ps1,請將指令碼路徑替換為實際位置後運行命令。

    • 若未指定版本,安裝指令碼將預設擷取並安裝阿里雲CLI的最新可用版本。預設安裝路徑為:C:\Users\<USERNAME>\AppData\Local\AliyunCLI

      powershell.exe -ExecutionPolicy Bypass -File C:\Example\Install-CLI-Windows.ps1
    • 使用-Version-InstallDir選項可指定阿里雲CLI的安裝版本和安裝目錄。訪問GitHub Release頁面可查看歷史可用版本。

      powershell.exe -ExecutionPolicy Bypass -File C:\Example\Install-CLI-Windows.ps1 -Version 3.0.277 -InstallDir "C:\ExampleDir\AliyunCLI"
    • 使用-Help選項可在終端中查看阿里雲CLI安裝指令碼的使用說明。

      powershell.exe -ExecutionPolicy Bypass -File C:\Example\Install-CLI-Windows.ps1 -Help

驗證安裝結果

重啟終端會話後執行如下命令,驗證阿里雲CLI是否安裝成功。

aliyun version

系統顯示類似如下阿里雲CLI版本號碼,表示安裝成功。

3.0.277