coreybutler/nvm-windows · error
error: failed to create backup directory: %v
Error message
error: failed to create backup directory: %v
What it means
Before overwriting the current installation, nvm-windows creates a second temp directory (nvm-backup-*) to hold a zip of the existing version. This error means os.MkdirTemp failed, i.e. the OS refused to create a directory under %TEMP%. Nothing has been modified yet at this point, so the installation is still intact.
Source
Thrown at src/upgrade/upgrade.go:469
// Debugging
if verbose {
tree(tmp, "downloaded files (extracted):")
nvmtestcmd := exec.Command(filepath.Join(tmp, "assets", "nvm.exe"), "version")
nvmtestcmd.Stdout = os.Stdout
nvmtestcmd.Stderr = os.Stderr
err = nvmtestcmd.Run()
if err != nil {
fmt.Println("error running nvm.exe:", err)
}
}
// Backup current version to zip
status <- Status{Text: "applying update..."}
currentExe, _ := os.Executable()
currentPath := filepath.Dir(currentExe)
bkp, err := os.MkdirTemp("", "nvm-backup-*")
if err != nil {
status <- Status{Err: fmt.Errorf("error: failed to create backup directory: %v\n", err)}
}
defer os.RemoveAll(bkp)
err = zipDirectory(currentPath, filepath.Join(bkp, "backup.zip"))
if err != nil {
status <- Status{Err: fmt.Errorf("error: failed to create backup: %v\n", err)}
}
os.MkdirAll(filepath.Join(currentPath, ".update"), os.ModePerm)
copyFile(filepath.Join(bkp, "backup.zip"), filepath.Join(currentPath, ".update", "nvm4w-backup.zip"))
// Copy the new files to the current directory
// copyFile(currentExe, fmt.Sprintf("%s.%s.bak", currentExe, version))
copyDirContents(filepath.Join(tmp, "assets"), currentPath)
copyFile(filepath.Join(tmp, "assets", "nvm.exe"), filepath.Join(currentPath, ".update/nvm.exe"))
if verbose {
nvmtestcmd := exec.Command(filepath.Join(currentPath, ".update/nvm.exe"), "version")View on GitHub (pinned to 5b18223ca1)
Solutions
- Free space on the drive hosting %TEMP% (often C:) and retry.
- Verify TEMP/TMP: echo %TEMP% then confirm the directory exists and you can create a folder in it.
- Run the upgrade from an elevated shell if ACLs are blocking directory creation.
- As a workaround set TEMP/TMP to a writable local path before running nvm.
Defensive patterns
Strategy: validation
Validate before calling
// Guarantee a writable temp root before upgrading
if err := os.MkdirTemp("", "nvm-probe-*"); err != nil {
fmt.Println("TEMP not writable:", err)
os.Setenv("TEMP", `D:\nvm-tmp`) // point somewhere writable
} Try / catch
Fail fast and clean — nothing has been modified when this fires. Report TEMP path and suggest freeing space or redirecting TEMP.
Prevention
- Keep the system drive from filling completely.
- Verify TEMP/TMP point at existing, writable local directories.
- Run upgrades elevated on locked-down machines.
When it happens
Trigger: TEMP/TMP environment variable pointing at a non-existent or unwritable directory; disk full on the temp drive; TEMP directory ACLs restricted (locked-down corporate machine); process running without rights to write to the resolved temp path.
Common situations: System drive full (most common on small VMs/CI); TEMP redirected to a ramdisk or network share that is unavailable; group policy restricting %TEMP% write access for the invoking user.
Related errors
- error: failed to copy update.exe: %v
- failed to open source file: %v
- failed to create destination file: %v
- failed to create destination directory %s: %v
- failed to get relative path for %s: %v
AI-assisted analysis of coreybutler/nvm-windows@5b18223ca1 (2026-08-15).
Data as JSON: /api/errors/e40f8401d9eaf99a.
Report an issue: GitHub.