abiosoft/colima · warning

%s exists, use --force to replace

Error message

%s exists, use --force to replace

What it means

`colima nerdctl install` writes a wrapper script to nerdctlCmdArgs.path (default /usr/local/bin/nerdctl). It refuses to overwrite an existing file unless --force is set OR the existing file is detected as a colima-generated script (it contains the marker string 'colima nerdctl '). This protects a real nerdctl binary or an unrelated file from being clobbered.

Source

Thrown at cmd/nerdctl.go:105

			if err := os.WriteFile(tmpFile, []byte("tmp"), 0777); err == nil {
				nerdctlCmdArgs.usrBinWriteable = true
				_ = os.Remove(tmpFile)
			}

			// check if the current file (if exists) is generated by colima
			// in such case no need for confirmation before overwrite
			// TODO: this is too basic, should be better
			if b, err := os.ReadFile(nerdctlCmdArgs.path); err == nil {
				if strings.Contains(string(b), "colima nerdctl ") {
					nerdctlCmdArgs.isColimaScript = true
				}
			}
		},

		RunE: func(cmd *cobra.Command, args []string) error {
			exists := false
			if _, err := os.Stat(nerdctlCmdArgs.path); err == nil && !nerdctlCmdArgs.force && !nerdctlCmdArgs.isColimaScript {
				return fmt.Errorf("%s exists, use --force to replace", nerdctlCmdArgs.path)
			} else if err == nil {
				exists = true
			}

			var values = struct {
				ColimaApp string
				Profile   string
			}{
				ColimaApp: osutil.Executable(),
				Profile:   config.CurrentProfile().ShortName,
			}
			buf, err := util.ParseTemplate(nerdctlScript, values)
			if err != nil {
				return fmt.Errorf("error applying nerdctl script template: %w", err)
			}

			// /usr/local/bin writeable i.e. sudo not needed
			// or user-specified install path, we assume user specified path is writeable

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Accept the backup-and-replace flow: `colima nerdctl install --force` — the old file is renamed to <path>.moved, not deleted
  2. Install elsewhere: `colima nerdctl install --path ~/bin/nerdctl` (ensure it is on PATH)
  3. If the existing file is a genuine nerdctl binary you want to keep, leave it and put the colima wrapper later in PATH order

Example fix

# before
$ colima nerdctl install
error: /usr/local/bin/nerdctl exists, use --force to replace

# after
$ colima nerdctl install --force   # old file kept as nerdctl.moved
Defensive patterns

Strategy: validation

Validate before calling

// pre-check the target the same way install does
if _, err := os.Stat(path); err == nil {
    b, _ := os.ReadFile(path)
    isColimaScript := strings.Contains(string(b), "colima nerdctl ")
    if !isColimaScript && !force {
        // pass --force, choose another --path, or skip install
    }
}

Prevention

When it happens

Trigger: An actual nerdctl binary already installed at /usr/local/bin/nerdctl (e.g. via brew or manual download); an unrelated file at a custom --path; the marker check failing because an older colima wrapper version lacked the 'colima nerdctl ' string.

Common situations: Reinstalling the wrapper over a brew-installed nerdctl; upgrading colima where the old wrapper used different wording; installing to a custom --path previously used for something else.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/ac51109f604a346f. Report an issue: GitHub.