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

  1. Verify in the same environment: kubectl version --client
  2. Install kubectl to a directory on PATH (https://kubernetes.io/docs/tasks/tools/), then restart the terminal and k9s
  3. 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

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


AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15). Data as JSON: /api/errors/3c46656ae3bbeb38. Report an issue: GitHub.