Alaya NeW Cloud

Install kubectl

Install kubectl on macOS / Linux x86-64 / Windows PowerShell — covers both the official Kubernetes endpoint and the Rancher China mirror

To use Virtual Kubernetes Service (VKS) by configuring environment variables, you first need to install kubectl. The steps below are organized by operating system.

  • For more kubectl installation details, see the official Install Tools guide.
  • The interface may differ slightly across operating systems and versions; defer to what you actually see on screen.

macOS

  1. Download the latest stable kubectl binary, download its checksum file, and verify the binary against the checksum. A successful verification prints kubectl: OK (highlighted in green below).

    Download and verify kubectl on macOS

    curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
    curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256"
    echo "$(cat kubectl.sha256)  kubectl" | shasum -a 256 --check

    Replace $(curl -L -s https://dl.k8s.io/release/stable.txt) with the version you want, for example 1.32.0.

  2. (If the directory does not exist locally) create /usr/local/bin and set its permissions, then move kubectl into /usr/local/bin/kubectl.

    Create the directory and move the binary

    sudo mkdir -p /usr/local/bin
    sudo chmod 755 /usr/local/bin
    sudo mv ./kubectl /usr/local/bin/kubectl
    sudo chown root: /usr/local/bin/kubectl
  3. Test the installed kubectl and confirm you have the latest version:

    kubectl version --client
  4. Remove the checksum file:

    rm kubectl.sha256

If your network is restricted or downloads are too slow, grab the appropriate package from the Rancher China community downloads (this example picks darwin-amd64-v1.32.3-kubectl):

Download from the Rancher China mirror

# Right-click the file to copy the download URL, then replace "rancher-path"
curl -LO "rancher-path"

# Move and grant execute permission
sudo mv darwin-amd64-v1.32.3-kubectl /usr/local/bin/kubectl
sudo chmod +x /usr/local/bin/kubectl
kubectl version --client

Linux x86-64

  1. Open a terminal and download the latest stable kubectl for Linux x86-64.

    Linux installation steps

    # Download from the official Kubernetes site
    curl -LO "https://dl.k8s.io/release/v1.32.0/bin/linux/amd64/kubectl"
    
    # Or use the Rancher China mirror
    curl -LO "https://rancher-mirror.rancher.cn/kubectl/v1.32.3/linux-amd64-v1.32.3-kubectl"
  2. Use mv to rename the downloaded file to kubectl (skip this step if you used the official Kubernetes URL):

    mv downloadfilename kubectl
  3. Add execute permission and move it onto the system path:

    chmod +x kubectl
    mv kubectl /usr/local/bin
  4. Verify the installation:

    kubectl version --client

Windows PowerShell

The example below installs kubectl on Windows 11.

  1. Create a new kubectl folder locally, open it, right-click an empty area, and choose "Open in Terminal" to launch PowerShell.

  2. In the terminal, download the latest stable kubectl (pick one):

    # Official Kubernetes site
    curl.exe -LO "https://dl.k8s.io/release/v1.32.0/bin/windows/amd64/kubectl.exe"
    
    # Or Rancher China mirror
    curl.exe -LO "https://rancher-mirror.rancher.cn/kubectl/v1.32.3/windows-amd64-v1.32.3-kubectl.exe"

    Replace v1.32.0 / v1.32.3 with the kubectl version you need.

  3. Rename the file to kubectl.exe:

    Rename to kubectl.exe

    Rename-Item -Path "my file.exe" -NewName "kubectl.exe"
  4. Set the environment variable:

    setx PATH "%PATH%;D:\kubectl"
  5. Verify the installation:

    kubectl version --client

    After updating the environment variable, you may need to open a new CMD / PowerShell window for it to take effect.

No curl? Configure PATH manually

  1. Download the latest kubectl, for example windows-amd64-v1.32.3-kubectl.exe, and rename it to kubectl.exe.

  2. Right-click [This PC → Properties] → [System → System Information] → "Advanced system settings".

  3. On the [System Properties] page, click [Environment Variables].

  4. Under "System variables", double-click Path to edit the environment variable, and add a new entry pointing to the directory that contains kubectl.exe (for example D:\kubectl).

    Configure PATH on Windows

    D:\kubectl is the directory containing kubectl.exe. Adjust it to match your setup.

Last updated on

Was this page helpful?

On this page