hashicorp/nomad · error

cannot remove existing nomad binary install - %s

Error message

cannot remove existing nomad binary install - %s

What it means

binaryInstall wraps the error from os.RemoveAll(opts.binaryPath), which clears the existing installation path before the new binary is renamed into place. If the old binary cannot be removed, the install stops to avoid overwriting a locked or protected file.

Source

Thrown at command/windows_service_install.go:357

	defer exeFile.Close()

	// Copy into a temporary file which can then be moved
	// into the correct location.
	dstFile, err := os.CreateTemp(os.TempDir(), "nomad*")
	if err != nil {
		return fmt.Errorf("cannot create copy - %s", err)
	}
	defer dstFile.Close()

	if _, err = io.Copy(dstFile, exeFile); err != nil {
		return fmt.Errorf("cannot write nomad binary for install - %s", err)
	}
	dstFile.Close()

	// With a copy ready to be moved into place, ensure that
	// the path is clear then move the file.
	if err = os.RemoveAll(opts.binaryPath); err != nil {
		return fmt.Errorf("cannot remove existing nomad binary install - %s", err)
	}

	if err = os.Rename(dstFile.Name(), opts.binaryPath); err != nil {
		return fmt.Errorf("cannot install new nomad binary - %s", err)
	}

	return nil
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Stop the nomad Windows service (or uninstall it) before running the installer
  2. Run the installer elevated as an account with permission to delete the target path
  3. Check the wrapped error for a sharing violation and identify the locking process (e.g. antivirus)
  4. Delete the old binary manually and re-run the install

Example fix

// before
nomad windows service install   # service still running, exe locked
// after
net stop nomad
nomad windows service install
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(binaryPath); err == nil {
    if err := syscall.Chmod(binaryPath, 0o666); err != nil { // or stop service first
        return fmt.Errorf("cannot touch existing binary: %v", err)
    }
}

Try / catch

if err := installCmd.Run(); err != nil {
    if strings.Contains(err.Error(), "cannot remove existing nomad binary") {
        // stop the nomad service, then retry
    }
}

Prevention

When it happens

Trigger: os.RemoveAll on the configured binary path fails because the running Nomad Windows service has the exe locked, a file-permission/ACL denies deletion, or the file is held by antivirus while performInstall is executing.

Common situations: Upgrading an existing Nomad service without stopping it first; installing over a path owned by another user; exe locked by an EDR scanner.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/83cdd967d1144f04. Report an issue: GitHub.