Skip to main content
📬 Get weekly Production AI insightsPractical notes on Kubernetes, AI infrastructure and platform engineering. No spam.Subscribe free
Platform Engineering

Install kubectl on Ubuntu (Step-by-Step 2026)

Install kubectl on Ubuntu with apt (pkgs.k8s.io), a direct download or snap. Copy-paste commands, checksum check, version skew, shell completion and fixes.

Luca Berton

· The Production AI Expert

Published ·Updated ·1 min read

Three ways to install kubectl on Ubuntu 24.04 and 22.04: the apt repository (recommended), a direct download, or snap. Pick one. All three end with the same kubectl binary.

# Add Kubernetes APT repository
sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

# Install kubectl
sudo apt-get update
sudo apt-get install -y kubectl

pkgs.k8s.io has one repository per Kubernetes minor version. Change v1.31 in both URLs to the minor version your cluster runs. On releases older than Ubuntu 22.04, /etc/apt/keyrings does not exist yet, so create it first with sudo mkdir -p -m 755 /etc/apt/keyrings.

Method 2: Direct Download

# Download the latest stable release (use arm64 instead of amd64 on ARM machines)
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

# Check the binary against its published checksum: expect "kubectl: OK"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check

# Install and clean up
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
rm kubectl kubectl.sha256

Method 3: Snap

sudo snap install kubectl --classic

Verify

kubectl version --client
kubectl cluster-info  # If connected to a cluster

Match kubectl to Your Cluster

kubectl is supported within one minor version of your cluster’s API server. A v1.31 kubectl works with v1.30, v1.31 and v1.32 control planes. kubectl version prints both the client and the server version, so check it once you are connected.

Enable Shell Completion

# Bash (needs the bash-completion package)
sudo apt-get install -y bash-completion
echo 'source <(kubectl completion bash)' >> ~/.bashrc
echo 'alias k=kubectl' >> ~/.bashrc
echo 'complete -o default -F __start_kubectl k' >> ~/.bashrc
source ~/.bashrc

# Zsh
echo 'source <(kubectl completion zsh)' >> ~/.zshrc

Upgrade kubectl

# APT: latest patch release of your current minor version
sudo apt-get update && sudo apt-get install --only-upgrade kubectl

# Snap
sudo snap refresh kubectl

To move APT to a new minor version, change the version in /etc/apt/sources.list.d/kubernetes.list, then run the upgrade again. For a direct download, repeat Method 2.

Troubleshooting

  • The connection to the server localhost:8080 was refused: kubectl is installed but has no kubeconfig. Copy your cluster’s config to ~/.kube/config, or point the KUBECONFIG variable at it.
  • E: Unable to locate package kubectl: the Kubernetes apt repository is missing, or you did not run sudo apt-get update after adding it.
  • kubectl: command not found after a direct download: check that /usr/local/bin is on your PATH with which kubectl.

Uninstall

sudo apt-get remove -y kubectl     # APT
sudo snap remove kubectl           # Snap
sudo rm /usr/local/bin/kubectl     # Direct download

Free 30-min Production AI consultation

Book Now