Here is how to install kubectl on Rocky Linux 9. Tested and verified.
Prerequisites
- Rocky Linux 9 installed and updated
- Root or sudo access
- Internet connection
Step 1: Update System
sudo dnf update -yStep 2: Add Official Repository
kubectl should be installed from the official Kubernetes package repository so you get the latest stable version and security updates.
# Create the Kubernetes repository definition
# This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/repodata/repomd.xml.key
EOF
v1.36selects the Kubernetes 1.36 package repository, the current stable minor version at the time of writing. To track a different minor version, replacev1.36in both thebaseurlandgpgkeylines, then re-rundnf update.
Step 3: Install kubectl
sudo dnf install -y kubectldnf reads the gpgkey URL from the repo file and imports/trusts the signing key automatically during install.
Step 4: Verify Installation
kubectl version --clientExpected output should show the installed client version.
Step 5: Enable Shell Completion
kubectl is a standalone CLI binary β it has no daemon and nothing to enable or start with systemd. Instead, set up Bash completion so you get tab-completion for commands, flags, and resource names.
# Install bash-completion if it isn't already present
sudo dnf install -y bash-completion
# Enable kubectl completion for the current user
echo 'source <(kubectl completion bash)' >> ~/.bashrc
echo 'alias k=kubectl' >> ~/.bashrc
echo 'complete -o default -F __start_kubectl k' >> ~/.bashrc
source ~/.bashrcTroubleshooting
GPG Key Import Failed
If dnf install reports a GPG key retrieval or signature error, confirm the repo file has the correct key URL and re-import the key manually:
cat /etc/yum.repos.d/kubernetes.repo
sudo rpm --import https://pkgs.k8s.io/core:/stable:/v1.36/rpm/repodata/repomd.xml.key
sudo dnf install -y kubectlPackage Not Found
If dnf reports Failed to synchronize cache for repo 'kubernetes' or No match for argument: kubectl, clear the cache, refresh metadata, and confirm the package is visible:
sudo dnf clean all
sudo dnf makecache
dnf repolist
dnf list kubectl --showduplicatesIf kubernetes.repo is missing, redo Step 2.
Uninstall
sudo dnf remove -y kubectlRelated Guides
About the Author
I am Luca Berton, AI and Cloud Advisor. Book a consultation to get help with your infrastructure setup.