{"record":{"id":"ac51109f604a346f","repo":"abiosoft/colima","slug":"s-exists-use-force-to-replace","errorCode":null,"errorMessage":"%s exists, use --force to replace","messagePattern":"(.+?) exists, use --force to replace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/nerdctl.go","lineNumber":105,"sourceCode":"\t\t\tif err := os.WriteFile(tmpFile, []byte(\"tmp\"), 0777); err == nil {\n\t\t\t\tnerdctlCmdArgs.usrBinWriteable = true\n\t\t\t\t_ = os.Remove(tmpFile)\n\t\t\t}\n\n\t\t\t// check if the current file (if exists) is generated by colima\n\t\t\t// in such case no need for confirmation before overwrite\n\t\t\t// TODO: this is too basic, should be better\n\t\t\tif b, err := os.ReadFile(nerdctlCmdArgs.path); err == nil {\n\t\t\t\tif strings.Contains(string(b), \"colima nerdctl \") {\n\t\t\t\t\tnerdctlCmdArgs.isColimaScript = true\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\texists := false\n\t\t\tif _, err := os.Stat(nerdctlCmdArgs.path); err == nil && !nerdctlCmdArgs.force && !nerdctlCmdArgs.isColimaScript {\n\t\t\t\treturn fmt.Errorf(\"%s exists, use --force to replace\", nerdctlCmdArgs.path)\n\t\t\t} else if err == nil {\n\t\t\t\texists = true\n\t\t\t}\n\n\t\t\tvar values = struct {\n\t\t\t\tColimaApp string\n\t\t\t\tProfile   string\n\t\t\t}{\n\t\t\t\tColimaApp: osutil.Executable(),\n\t\t\t\tProfile:   config.CurrentProfile().ShortName,\n\t\t\t}\n\t\t\tbuf, err := util.ParseTemplate(nerdctlScript, values)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error applying nerdctl script template: %w\", err)\n\t\t\t}\n\n\t\t\t// /usr/local/bin writeable i.e. sudo not needed\n\t\t\t// or user-specified install path, we assume user specified path is writeable","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/nerdctl.go#L87-L123","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Accept the backup-and-replace flow: `colima nerdctl install --force` — the old file is renamed to <path>.moved, not deleted","Install elsewhere: `colima nerdctl install --path ~/bin/nerdctl` (ensure it is on PATH)","If the existing file is a genuine nerdctl binary you want to keep, leave it and put the colima wrapper later in PATH order"],"exampleFix":"# before\n$ colima nerdctl install\nerror: /usr/local/bin/nerdctl exists, use --force to replace\n\n# after\n$ colima nerdctl install --force   # old file kept as nerdctl.moved","handlingStrategy":"validation","validationCode":"// pre-check the target the same way install does\nif _, err := os.Stat(path); err == nil {\n    b, _ := os.ReadFile(path)\n    isColimaScript := strings.Contains(string(b), \"colima nerdctl \")\n    if !isColimaScript && !force {\n        // pass --force, choose another --path, or skip install\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Expect this guard whenever a real (non-colima) nerdctl binary occupies the path — use --force and rely on the automatic .moved backup","Install wrappers to a dedicated path (--path) to avoid colliding with brew-managed binaries"],"tags":["colima","nerdctl","installation","filesystem","cli"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}