{"record":{"id":"5e0bea5cec27c9aa","repo":"direnv/direnv","slug":"could-not-find-a-default-editor-in-the-path","errorCode":null,"errorMessage":"could not find a default editor in the PATH","messagePattern":"could not find a default editor in the PATH","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cmd_edit.go","lineNumber":55,"sourceCode":"\tif len(args) > 1 {\n\t\trcPath = args[1]\n\t\tfi, _ := os.Stat(rcPath)\n\t\tif fi != nil && fi.IsDir() {\n\t\t\trcPath = filepath.Join(rcPath, \".envrc\")\n\t\t}\n\t} else {\n\t\tif foundRC == nil {\n\t\t\treturn fmt.Errorf(\".envrc or .env not found. Use `direnv edit .` to create a new .envrc in the current directory\")\n\t\t}\n\t\trcPath = foundRC.path\n\t}\n\n\teditor := env[\"EDITOR\"]\n\tif editor == \"\" {\n\t\tlogError(config, \"$EDITOR not found.\")\n\t\teditor = detectEditor(env[\"PATH\"])\n\t\tif editor == \"\" {\n\t\t\terr = fmt.Errorf(\"could not find a default editor in the PATH\")\n\t\t\treturn\n\t\t}\n\t}\n\n\trun := fmt.Sprintf(\"%s %s\", editor, BashEscape(rcPath))\n\n\t// G204: Subprocess launched with function call as argument or cmd arguments\n\t// #nosec\n\tcmd := exec.Command(config.BashPath, \"-c\", run)\n\tcmd.Stdin = os.Stdin\n\tcmd.Stdout = os.Stdout\n\tcmd.Stderr = os.Stderr\n\tif err = cmd.Run(); err != nil {\n\t\treturn\n\t}\n\n\tfoundRC, err = FindRC(rcPath, config)\n\tlogDebug(\"foundRC: %#v\", foundRC)","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/direnv/direnv/blob/b00e451f547f39be7ab836d969054114a465a0f9/internal/cmd/cmd_edit.go#L37-L73","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n$ direnv edit .envrc\nError: could not find a default editor in the PATH\n// after\n$ export EDITOR=nano\n$ direnv edit .envrc","handlingStrategy":"validation","validationCode":"#!/bin/bash\n: \"${EDITOR:=nano}\"   # or vim/vi\ncommand -v \"$EDITOR\" >/dev/null || { echo \"EDITOR $EDITOR not on PATH\" >&2; exit 1; }\nexport EDITOR\ndirenv edit","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"direnv\", \"edit\", rcPath).CombinedOutput()\nif err != nil && strings.Contains(string(out), \"could not find a default editor\") {\n    return fmt.Errorf(\"set $EDITOR or install an editor\")\n}","preventionTips":["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"],"tags":["direnv","editor","environment"],"backgroundTag":"missing-editor-env-var","analyzedSha":"b00e451f547f39be7ab836d969054114a465a0f9","analyzedAt":"2026-09-05T21:39:49.983Z","contentChangedAt":"2026-09-05T21:39:49.983Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}