kubectl command not found - Mac

Page content

How to Install kubectl Command on Mac

If you’re encountering the “kubectl command not found” error on your Mac, don’t worry. kubectl is a command-line tool that allows you to interact with Kubernetes clusters. Here’s a step-by-step guide on how to install kubectl on a Mac:

Step 1: Install Homebrew

Homebrew is a package manager for macOS that makes it easy to install command-line tools. If you don’t have Homebrew installed, you can do so by running the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install kubectl

Once Homebrew is installed, you can use it to install kubectl by running the following command:

brew install kubectl

Step 3: Verify Installation

After the installation is complete, you can verify that kubectl is installed by checking its version:

kubectl version --client

Step 4: Add kubectl to PATH (Optional)

To use kubectl without specifying the full path to the executable, you can add it to your PATH. You can do this by adding the following line to your ~/.bash_profile or ~/.zshrc file:

export PATH=$PATH:/usr/local/bin

Alternative Solution for Non-Homebrew Users

If you prefer not to use Homebrew, you can download the kubectl binary directly from the Kubernetes GitHub repository. Here’s how you can do it:

  1. Go to the Kubernetes GitHub releases page and download the appropriate binary for your macOS version.
  2. Extract the downloaded file and move the kubectl binary to a directory in your PATH, such as /usr/local/bin.

Conclusion

By following the steps outlined in this tutorial, you should now have kubectl installed and ready to use on your Mac. kubectl is a powerful tool for managing Kubernetes clusters, and having it installed on your machine will enable you to interact with Kubernetes resources easily.