{"record":{"id":"10f5524a4709b75b","repo":"hashicorp/nomad","slug":"cannot-install-new-nomad-binary-s","errorCode":null,"errorMessage":"cannot install new nomad binary - %s","messagePattern":"cannot install new nomad binary - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":361,"sourceCode":"\tdstFile, err := os.CreateTemp(os.TempDir(), \"nomad*\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot create copy - %s\", err)\n\t}\n\tdefer dstFile.Close()\n\n\tif _, err = io.Copy(dstFile, exeFile); err != nil {\n\t\treturn fmt.Errorf(\"cannot write nomad binary for install - %s\", err)\n\t}\n\tdstFile.Close()\n\n\t// With a copy ready to be moved into place, ensure that\n\t// the path is clear then move the file.\n\tif err = os.RemoveAll(opts.binaryPath); err != nil {\n\t\treturn fmt.Errorf(\"cannot remove existing nomad binary install - %s\", err)\n\t}\n\n\tif err = os.Rename(dstFile.Name(), opts.binaryPath); err != nil {\n\t\treturn fmt.Errorf(\"cannot install new nomad binary - %s\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":343,"sourceCodeEnd":366,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L343-L366","documentation":"binaryInstall wraps the error from os.Rename(dstFile.Name(), opts.binaryPath), which moves the staged temp copy to the final install path. On Windows, rename across devices or onto a locked target fails, so the new binary could not be installed. The wrapped error explains why.","triggerScenarios":"os.Rename fails when the temp dir and binaryPath are on different volumes (rename is not cross-device on Windows), the target path still exists/is locked, or permissions deny the move during binaryInstall.","commonSituations":"TMP on a different drive than the install directory; leftover target file that RemoveAll missed; target locked by the still-running service.","solutions":["Ensure the temp directory and the install path are on the same volume (set TMP accordingly)","Stop the running nomad service so the target path is not locked","Run elevated so the rename is permitted","Remove any residual file at the target path manually, then retry the install"],"exampleFix":"// before: TMP on D: while binaryPath on C:\nset TMP=D:\\tmp\n// after: same volume as install target\nset TMP=C:\\Windows\\Temp","handlingStrategy":"validation","validationCode":"td := os.TempDir()\nif filepath.VolumeName(td) != filepath.VolumeName(binaryPath) {\n    return fmt.Errorf(\"temp dir %s and install path %s on different volumes\", td, binaryPath)\n}","typeGuard":null,"tryCatchPattern":"if err := installCmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"cannot install new nomad binary\") {\n        // align TMP volume with install path, unlock target, retry\n    }\n}","preventionTips":["Keep TMP on the same volume as the install directory","Clear any residual file at the target path before install","Stop the running service so the target is not locked"],"tags":["go","windows","filesystem","rename"],"backgroundTag":"file-rename-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}