Fix "kubectl: command not found" on Linux, Mac and Windows
"kubectl: command not found" means your shell cannot find a program called kubectl in any folder on your PATH. Install the official binary for your system (Linux, macOS or Windows), put it in a PATH folder such as /usr/local/bin, open a new terminal, and check with kubectl version --client. Then connect it to your cluster with aws eks update-kubeconfig, gcloud container clusters get-credentials or az aks get-credentials.
Quick answer (Linux x86_64)
curl -LO "https://dl.k8s.io/release/$(curl -Ls https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
aws eks update-kubeconfig --region ap-south-1 --name lab-cluster
kubectl get nodes
A live example first
A student logs in to a fresh Amazon Linux 2023 EC2 instance to manage the class EKS cluster:
kubectl get nodes
-bash: kubectl: command not found
Check where the shell is looking:
echo $PATH
which kubectl
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
/usr/bin/which: no kubectl in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin)
So kubectl is simply not installed. Install it, prove it, connect it:
curl -LO "https://dl.k8s.io/release/v1.30.4/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
Client Version: v1.30.4
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
aws eks update-kubeconfig --region ap-south-1 --name lab-cluster
kubectl get nodes
NAME STATUS ROLES AGE VERSION
ip-10-0-1-25.ap-south-1.compute.internal Ready <none> 3d v1.30.2-eks-1552ad0
Done. Friends, notice we picked v1.30 to match the EKS cluster version.
Why does the shell say command not found?
"command not found" is a PATH problem. Install the binary, put it on PATH, then connect a kubeconfig.
When you type a command, the shell checks each folder in PATH, from left to right, for a file with that name. If no folder has it, you get "command not found". So there are only two possible problems: kubectl is not installed, or it is installed in a folder that is not on PATH (for example, it was downloaded to ~/Downloads).
Install kubectl on your system
Linux (Ubuntu, Amazon Linux, RHEL)
- Check your CPU type with
uname -m(x86_64= amd64,aarch64= arm64). - Download the matching binary from
dl.k8s.io. - Run
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl. - Run
kubectl version --client.
On a Graviton (arm64) EC2 instance, change amd64 to arm64 in the URL, or you will see cannot execute binary file: Exec format error.
macOS
brew install kubectl
kubectl version --client
If brew itself is "not found" on an Apple Silicon Mac, add eval "$(/opt/homebrew/bin/brew shellenv)" to ~/.zprofile.
Windows 10 / 11
winget install -e --id Kubernetes.kubectl
Close PowerShell, open a new one, then:
where.exe kubectl
kubectl version --client
If you downloaded kubectl.exe by hand, put it in a folder like C:\tools\k8s and add that folder in System Properties → Environment Variables → Path.
minikube and Docker Desktop
- minikube ships its own kubectl:
minikube kubectl -- get pods -A. - Docker Desktop installs kubectl when you enable Kubernetes in Settings.
Connect kubectl to your cloud cluster
Amazon EKS
aws eks update-kubeconfig --region ap-south-1 --name lab-cluster
If you then see You must be logged in to the server (Unauthorized), your IAM user or role has no access entry in the cluster. Ask the cluster admin to add it.
Google GKE
gcloud components install gke-gcloud-auth-plugin
gcloud container clusters get-credentials lab-cluster --region asia-south1
Without the auth plugin, kubectl prints an error that gke-gcloud-auth-plugin was not found.
Azure AKS
az aks install-cli
az aks get-credentials --resource-group lab-rg --name lab-cluster
Errors you may see next
| Message | Meaning | Fix |
|---|---|---|
kubectl: command not found |
Not installed, or not on PATH | Install and add to PATH |
Exec format error |
Wrong CPU architecture | Download arm64 or amd64 correctly |
connection to the server localhost:8080 was refused |
No kubeconfig | update-kubeconfig / get-credentials |
Unauthorized |
Identity not allowed in cluster | EKS access entry or RBAC |
gke-gcloud-auth-plugin not found |
GKE plugin missing | gcloud components install gke-gcloud-auth-plugin |
Real example: why version skew matters
The Kubernetes project officially supports kubectl within one minor version of the cluster. Amazon EKS, GKE and AKS all upgrade clusters on a regular schedule, and old clients can stop working when an API is removed. For example, Kubernetes 1.24 removed the old client.authentication.k8s.io/v1alpha1 auth API, and many teams found their old kubeconfig files broken after upgrading. Keep kubectl updated along with your cluster.
Mistakes students make (and how to avoid them)
- Running
sudo kubectlafter installing in a user folder.sudouses a different PATH and a different home folder, so it cannot find your binary or your~/.kube/config. Install to/usr/local/binand run kubectl without sudo. - Keeping the old terminal open. PATH changes only load in a new terminal. Close it and open a new one before you test.
- Downloading the HTML page instead of the binary. If
file kubectlsays "HTML document", the URL was wrong. Download again withcurl -LOand the exact URL. - Installing two versions.
which -a kubectllists every copy on PATH. Remove the old one so you always run the version you expect. - Sharing one admin kubeconfig. Every learner should connect with their own IAM identity, so access can be removed per person.
Summary table
| System | Install | Check |
|---|---|---|
| Linux | curl from dl.k8s.io + sudo install |
kubectl version --client |
| macOS | brew install kubectl |
which kubectl |
| Windows | winget install Kubernetes.kubectl |
where.exe kubectl |
| EKS | aws eks update-kubeconfig |
kubectl get nodes |
| GKE | gcloud ... get-credentials + auth plugin |
kubectl get nodes |
| AKS | az aks get-credentials |
kubectl get nodes |
Quick quiz: check what you learned
What does "kubectl: command not found" really mean?
- The shell cannot find it in PATH
- The cluster API server is down
- The kubeconfig file is corrupted
- The pod has no network policy
Show answer
A. The shell only looks in PATH folders, so kubectl is missing or in another folder.
Which command connects kubectl to an Amazon EKS cluster?
- aws eks update-kubeconfig
- kubectl create cluster eks
- docker login eks.amazonaws
- minikube start --eks
Show answer
A. The AWS CLI writes the cluster details into ~/.kube/config.
kubectl says localhost:8080 connection refused. Why?
- No kubeconfig is set up yet
- The binary is not on PATH
- The image tag is mistyped
- The node memory is too low
Show answer
A. Without a kubeconfig, kubectl falls back to localhost:8080, where nothing listens.
How close should the kubectl version be to the cluster?
- Within one minor version
- Exactly the same patch
- Any version will work
- At least two versions newer
Show answer
A. Kubernetes supports kubectl within one minor version of the API server.
Learn it properly
This guide is the short path. The free DevOps course covers Kubernetes step by step, with labs:
Frequently asked questions
Why does it say kubectl: command not found?
The shell cannot find a program called kubectl in any PATH folder. Either it is not installed, or it is installed in a folder that is not on PATH.
How do I install kubectl on Ubuntu?
Download the binary from dl.k8s.io, run sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl, then kubectl version --client.
How do I install kubectl on Windows?
Run winget install -e --id Kubernetes.kubectl, then open a new PowerShell window and run kubectl version --client.
I use minikube. Do I need kubectl?
minikube includes it. You can run minikube kubectl -- get pods, or install kubectl separately.
kubectl works but says connection refused on localhost:8080?
kubectl is installed but has no kubeconfig. Connect it to a cluster with your cloud CLI, or start minikube.
Which kubectl version should I use?
Stay within one minor version of your cluster. For an EKS 1.30 cluster, kubectl 1.29, 1.30 or 1.31 is fine.