{"record":{"id":"b1b0efaa487fe0f4","repo":"hashicorp/nomad","slug":"could-not-create-binary-install-directory-s","errorCode":null,"errorMessage":"could not create binary install directory - %s","messagePattern":"could not create binary install directory - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":331,"sourceCode":"\t// will be installed for the service to call.\n\texePath, err := os.Executable()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot detect current nomad path - %s\", err)\n\t}\n\n\t// Build the needed paths\n\tif opts.installDir == \"\" {\n\t\topts.installDir = winsvc.WINDOWS_INSTALL_BIN_DIRECTORY\n\t}\n\topts.installDir, err = c.winPaths.Expand(opts.installDir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot generate binary install path - %s\", err)\n\t}\n\topts.binaryPath = filepath.Join(opts.installDir, \"nomad.exe\")\n\n\t// Ensure the install directory exists\n\tif err = c.winPaths.CreateDirectory(opts.installDir, false); err != nil {\n\t\treturn fmt.Errorf(\"could not create binary install directory - %s\", err)\n\t}\n\n\t// Create a new copy of the current binary to install\n\texeFile, err := os.Open(exePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot open current nomad path for install - %s\", err)\n\t}\n\tdefer exeFile.Close()\n\n\t// Copy into a temporary file which can then be moved\n\t// into the correct location.\n\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 {","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L313-L349","documentation":"After expanding the install dir, binaryInstall ensures the directory exists via winPaths.CreateDirectory(opts.installDir, false). This error wraps that call's failure — Nomad cannot create the folder that will hold the installed service binary.","triggerScenarios":"Running 'nomad windows service install' when the install directory cannot be created: no write permission in the parent (e.g. Program Files without elevation), a file already exists at that path, or the drive is unavailable/read-only.","commonSituations":"Installing into C:\\Program Files from a non-admin shell; custom -install-dir in a protected location; a file conflicting with the target directory name; full disk.","solutions":["Run the install from an elevated (Administrator) prompt","Choose a writable -install-dir or use the default bin directory","Check for a conflicting file at the install-dir path","Verify the target drive exists and has free space"],"exampleFix":"// before (non-elevated)\nnomad windows service install -install-dir \"C:\\Program Files\\nomad\"\n// after (elevated shell)\nnomad windows service install -install-dir \"C:\\Program Files\\nomad\"","handlingStrategy":"validation","validationCode":"// Pre-check install dir writability and conflicts\nif fi, err := os.Stat(installDir); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", installDir)\n}\nprobe := filepath.Join(installDir, \".nomad_probe\")\nif err := os.WriteFile(probe, nil, 0o600); err != nil {\n    return fmt.Errorf(\"install dir not writable: %w\", err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install from an elevated prompt when targeting Program Files","Pre-create the install directory with correct ACLs","Check free disk space before install","Avoid read-only or removable media as install targets"],"tags":["windows","directory","permissions"],"backgroundTag":"directory-creation-permission-denied","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"}