derailed/k9s · error
kubectl command is not in your path: %w
Error message
kubectl command is not in your path: %w
What it means
exec.LookPath("kubectl") returned a non-sentinel error: no kubectl executable exists anywhere on PATH. runK() backs every feature where k9s shells out to kubectl (in-pod shell, node shell plumbing, kubectl prompt commands), so those features are dead until kubectl is installed.
Source
Thrown at internal/view/exec.go:64
type shellOpts struct {
clear, background bool
pipes []string
binary string
banner string
args []string
}
func (s shellOpts) String() string {
return fmt.Sprintf("%s %s", s.binary, strings.Join(s.args, " "))
}
func runK(a *App, opts *shellOpts) error {
bin, err := exec.LookPath("kubectl")
if errors.Is(err, exec.ErrDot) {
return fmt.Errorf("kubectl command must not be in the current working directory: %w", err)
}
if err != nil {
return fmt.Errorf("kubectl command is not in your path: %w", err)
}
args := []string{opts.args[0]}
if u, err := a.Conn().Config().ImpersonateUser(); err == nil {
args = append(args, "--as", u)
}
if g, err := a.Conn().Config().ImpersonateGroups(); err == nil {
args = append(args, "--as-group", g)
}
if isInsecure := a.Conn().Config().Flags().Insecure; isInsecure != nil && *isInsecure {
args = append(args, "--insecure-skip-tls-verify")
}
args = append(args, "--context", a.Config.K9s.ActiveContextName())
if cfg := a.Conn().Config().Flags().KubeConfig; cfg != nil && *cfg != "" {
args = append(args, "--kubeconfig", *cfg)
}
if len(args) > 0 {
opts.args = append(args, opts.args[1:]...)
}View on GitHub (pinned to 2d3ccc6ba2)
Solutions
- Verify in the same environment: kubectl version --client
- Install kubectl to a directory on PATH (https://kubernetes.io/docs/tasks/tools/), then restart the terminal and k9s
- If installed via a version manager, ensure its bin dir is exported in the environment k9s actually inherits (check with :!echo $PATH inside k9s)
Example fix
# before $ k9s # shell command fails: kubectl not in PATH $ which kubectl (not found) # after $ 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 $ k9s
Defensive patterns
Strategy: validation
Validate before calling
if _, err := exec.LookPath("kubectl"); err != nil {
return fmt.Errorf("kubectl not found on PATH %q — install it before using shell features", os.Getenv("PATH"))
} Prevention
- Verify kubectl version --client in the exact environment k9s inherits (GUI launchers strip PATH)
- Install kubectl before relying on k9s shell/exec features
- Use :!echo $PATH inside k9s to confirm the process sees your PATH
When it happens
Trigger: Pressing 's' (shell) on a container or running a :!kubectl ... command on a workstation where kubectl is not installed, not executable, or PATH inside the k9s process differs from the login shell (launched from a GUI launcher, snap wrapper, or service with a minimal PATH).
Common situations: New machines without the CLI; kubectl installed via asdf/nvm shim not on the GUI session's PATH; container images running k9s without kubectl; typo'd PATH in shell rc files.
Related errors
- kubectl command must not be in the current working directory
- shell exec failed: %w
- command failed. Check k9s logs: %w
- node is cordoned
- namespace not ready
AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15).
Data as JSON: /api/errors/3c46656ae3bbeb38.
Report an issue: GitHub.