direnv/direnv · error
could not find a default editor in the PATH
Error message
could not find a default editor in the PATH
What it means
After EDITOR is empty, direnv falls back to detectEditor(PATH) to pick a sensible default editor. If neither EDITOR nor any known editor binary exists on PATH, cmdEditAction returns 'could not find a default editor in the PATH'.
Source
Thrown at internal/cmd/cmd_edit.go:55
if len(args) > 1 {
rcPath = args[1]
fi, _ := os.Stat(rcPath)
if fi != nil && fi.IsDir() {
rcPath = filepath.Join(rcPath, ".envrc")
}
} else {
if foundRC == nil {
return fmt.Errorf(".envrc or .env not found. Use `direnv edit .` to create a new .envrc in the current directory")
}
rcPath = foundRC.path
}
editor := env["EDITOR"]
if editor == "" {
logError(config, "$EDITOR not found.")
editor = detectEditor(env["PATH"])
if editor == "" {
err = fmt.Errorf("could not find a default editor in the PATH")
return
}
}
run := fmt.Sprintf("%s %s", editor, BashEscape(rcPath))
// G204: Subprocess launched with function call as argument or cmd arguments
// #nosec
cmd := exec.Command(config.BashPath, "-c", run)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err = cmd.Run(); err != nil {
return
}
foundRC, err = FindRC(rcPath, config)
logDebug("foundRC: %#v", foundRC)View on GitHub (pinned to b00e451f54)
Solutions
- Set EDITOR: export EDITOR=vim (or nano/code), then retry
- Install an editor (e.g. apt install nano) so detection succeeds
- Ensure PATH includes the directory containing your editor binary
Example fix
// before $ direnv edit .envrc Error: could not find a default editor in the PATH // after $ export EDITOR=nano $ direnv edit .envrc
Defensive patterns
Strategy: validation
Validate before calling
#!/bin/bash
: "${EDITOR:=nano}" # or vim/vi
command -v "$EDITOR" >/dev/null || { echo "EDITOR $EDITOR not on PATH" >&2; exit 1; }
export EDITOR
direnv edit Try / catch
out, err := exec.Command("direnv", "edit", rcPath).CombinedOutput()
if err != nil && strings.Contains(string(out), "could not find a default editor") {
return fmt.Errorf("set $EDITOR or install an editor")
} Prevention
- Always export EDITOR in shell profiles and CI containers
- Verify command -v "$EDITOR" succeeds in minimal images
- Install at least one common editor in containers used for dev
- Avoid sudo-sanitized environments that strip EDITOR
When it happens
Trigger: Running `direnv edit` with $EDITOR unset (or empty) and none of the editors direnv knows how to detect (vim, vi, emacs, nano, etc.) present in $PATH.
Common situations: Minimal containers/CI images without any editor installed; non-interactive shells with a stripped PATH; running direnv via sudo with a sanitized env clearing EDITOR.
Related errors
- couldn't find a configuration directory for direnv
- missing PATH argument
- invalid arguments
- executable file not found in $PATH
- the gzenv shell doesn't support hooking
AI-assisted analysis of direnv/direnv@b00e451f54 (2026-09-05).
Data as JSON: /api/errors/5e0bea5cec27c9aa.
Report an issue: GitHub.