abiosoft/colima · error
error backing up existing file: %w
Error message
error backing up existing file: %w
What it means
In the no-sudo branch of `colima nerdctl install` (taken when /usr/local/bin is writable OR a custom --path is given), an existing target file is first backed up with os.Rename(path, path+".moved"). This error wraps a rename failure: the containing directory is not actually writable, the file is locked, or the custom path's directory does not exist.
Source
Thrown at cmd/nerdctl.go:127
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
if nerdctlCmdArgs.usrBinWriteable || nerdctlCmdArgs.path != nerdctlDefaultInstallPath {
if exists {
if err := os.Rename(nerdctlCmdArgs.path, nerdctlCmdArgs.path+".moved"); err != nil {
return fmt.Errorf("error backing up existing file: %w", err)
}
}
if err := fsutil.MkdirAll("/usr/local/bin", 0755); err != nil {
return nil
}
return os.WriteFile(nerdctlCmdArgs.path, buf, 0755)
}
// sudo is needed for the default path
log.Println("/usr/local/bin not writable, sudo password required to install nerdctl binary")
if exists && !nerdctlCmdArgs.isColimaScript {
c := cli.CommandInteractive("sudo", "mv", nerdctlCmdArgs.path, nerdctlCmdArgs.path+".moved")
if err := c.Run(); err != nil {
return fmt.Errorf("error backing up existing file: %w", err)
}
}
// prepare dir
{View on GitHub (pinned to c3a5f9184d)
Solutions
- Ensure the parent directory of --path exists and is writable: mkdir -p the dir and touch a probe file
- Use the default path and let the sudo flow handle it (drop --path), or fix the directory permissions
- Pre-move the old file yourself (mv <path> <path>.moved) and re-run `colima nerdctl install --force`
Example fix
# before $ colima nerdctl install --path /opt/bin/nerdctl error: error backing up existing file: rename ...: no such file or directory # after $ sudo mkdir -p /opt/bin $ colima nerdctl install --path /opt/bin/nerdctl --force
Defensive patterns
Strategy: validation
Validate before calling
// verify rename-ability of the target dir before install
func dirWritable(dir string) bool {
f, err := os.CreateTemp(dir, ".colima-probe-*")
if err != nil {
return false
}
return os.Remove(f.Name()) == nil
}
if !dirWritable(filepath.Dir(path)) {
// mkdir -p the dir, chmod it, or switch to the default sudo flow
} Try / catch
if err := installCmd.Execute(); err != nil {
if strings.Contains(err.Error(), "error backing up existing file") && errors.Is(err, fs.ErrPermission) {
// pre-move the file manually or fix dir permissions, then retry
}
} Prevention
- Ensure the parent of a custom --path exists (mkdir -p) before installing
- Verify write access with a temp-file probe, not just an os.Stat on the directory
- Pre-move existing targets yourself when automating installs
When it happens
Trigger: A custom --path whose parent directory does not exist (rename fails with ENOENT); --path pointing into a read-only mount; the writability probe passing but SIP/permissions still denying rename on macOS; antivirus/file-watcher holding the file open.
Common situations: `colima nerdctl install --path ~/some/missing/dir/nerdctl`; systems where /usr/local/bin ownership changed after the probe; corporate endpoint protection locking new executables.
Related errors
- %s exists, use --force to replace
- error reading ssh config: %w
- error modifying %s: %w
- error preparing to copy VM: %w
- config missing for colima profile '%s': %w
AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15).
Data as JSON: /api/errors/fcd52bc2867c2a98.
Report an issue: GitHub.