lima-vm/lima · error

could not detect a text editor binary, try setting $EDITOR

Error message

could not detect a text editor binary, try setting $EDITOR

What it means

OpenEditor launches an interactive editor (via editorcmd.Detect()) to modify YAML content; it returns this error when no editor binary can be found in the environment. Detect() relies on $EDITOR/$VISUAL or well-known editors being installed.

Source

Thrown at pkg/editutil/editutil.go:63

	configDir, err := dirnames.LimaConfigDir()
	if err != nil {
		s += "# WARNING: failed to load the config dir\n"
		s += "\n"
		return s
	}

	s += fileWarning(filepath.Join(configDir, filenames.Default))
	s += fileWarning(filepath.Join(configDir, filenames.Override))
	return s
}

// OpenEditor opens an editor, and returns the content (not path) of the modified yaml.
//
// OpenEditor returns nil when the file was saved as an empty file, optionally with whitespaces.
func OpenEditor(ctx context.Context, content []byte, hdr string) ([]byte, error) {
	editor := editorcmd.Detect()
	if editor == "" {
		return nil, errors.New("could not detect a text editor binary, try setting $EDITOR")
	}
	tmpYAMLFile, err := os.CreateTemp("", "lima-editor-")
	if err != nil {
		return nil, err
	}
	tmpYAMLPath := tmpYAMLFile.Name()
	defer os.RemoveAll(tmpYAMLPath)
	if _, err := tmpYAMLFile.Write(append([]byte(hdr), content...)); err != nil {
		tmpYAMLFile.Close()
		return nil, err
	}
	if err := tmpYAMLFile.Close(); err != nil {
		return nil, err
	}

	editorCmd := exec.CommandContext(ctx, editor, tmpYAMLPath)
	editorCmd.Env = os.Environ()
	editorCmd.Stdin = os.Stdin

View on GitHub (pinned to dd909d0973)

Solutions

  1. Export EDITOR to an installed editor binary, e.g. `export EDITOR=vim` (or nano)
  2. Install an editor (apt install vim / nano) if none exists
  3. Set VISUAL if EDITOR is ignored in your shell environment
  4. Pipe YAML via stdin/file instead of the interactive edit flow when no TTY/editor is available

Example fix

// before
limactl edit default  // fails: could not detect a text editor binary
// after
export EDITOR=vim
limactl edit default
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("EDITOR") == "" && os.Getenv("VISUAL") == "" {
    if _, err := exec.LookPath("vi"); err != nil {
        return errors.New("no editor: set $EDITOR or install one")
    }
}

Try / catch

content, err := editutil.OpenEditor(ctx, yaml, hdr)
if err != nil {
    if err.Error() == "could not detect a text editor binary, try setting $EDITOR" {
        return fmt.Errorf("set $EDITOR and retry: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling OpenEditor (used by limactl edit and template creation flows via editAction / chooseNextCreatorState) in an environment where $EDITOR and $VISUAL are unset and no common editor binary (vi, nano, vim, etc.) is on PATH.

Common situations: Running lima inside minimal containers, CI jobs, or slimmed server images without any editor installed; non-interactive SSH shells where $EDITOR is not exported.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/312f2bf5b01f36d9. Report an issue: GitHub.