{"record":{"id":"85fe2573bfc55570","repo":"jdx/mise","slug":"cannot-link-name-these-files-already-exist-and","errorCode":null,"errorMessage":"cannot link {name}: these files already exist and were not created by mise or brew:\n{}\nRemove or rename them, then re-run `mise bootstrap packages apply`","messagePattern":"cannot link (.+?): these files already exist and were not created by mise or brew:\n(.+?)\nRemove or rename them, then re-run `mise bootstrap packages apply`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/pour.rs","lineNumber":597,"sourceCode":"                let dest = prefix_path.join(rel);\n                if !can_overwrite(&dest) {\n                    conflicts.push(dest);\n                } else {\n                    links.push((dest, entry.path().to_path_buf()));\n                }\n            }\n        }\n        let linked = prefix::linked_keg_record(name);\n        if can_overwrite(&linked) {\n            links.push((linked, keg.clone()));\n        } else {\n            conflicts.push(linked);\n        }\n    }\n    if !conflicts.is_empty() {\n        // nothing has been linked yet, and the caller rolls the keg back on\n        // this error — so don't claim it remains usable\n        bail!(\n            \"cannot link {name}: these files already exist and were not created by mise or brew:\\n{}\\n\\\n             Remove or rename them, then re-run `mise bootstrap packages apply`\",\n            conflicts\n                .iter()\n                .map(|p| format!(\"  {}\", p.display()))\n                .collect::<Vec<_>>()\n                .join(\"\\n\"),\n        );\n    }\n    // remember every symlink we overwrite (upgrades replace the previous\n    // version's links, opt included) so a failed link restores all of them\n    let mut created: Vec<PathBuf> = vec![];\n    let mut replaced: Vec<(PathBuf, PathBuf)> = vec![];\n    let mut failure: Option<eyre::Report> = None;\n    for (dest, target) in &links {\n        let made = (|| -> Result<()> {\n            // a parent that is a brew directory symlink must become a real\n            // directory first — otherwise the link below would be created","sourceCodeStart":579,"sourceCodeEnd":615,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/brew/pour.rs#L579-L615","documentation":"When linking a keg into the brew prefix, pour checks each target path; if a file or symlink already exists that was not created by mise or brew, it refuses to link and lists the conflicting paths. Nothing has been linked yet — the caller rolls the keg back — so the error lists files to remove and the exact command to re-run.","triggerScenarios":"Running `mise bootstrap packages apply` on a machine where a manually installed copy of the tool (make install, a different package manager, hand-placed symlinks) already occupies files under the brew prefix that link_keg would create.","commonSituations":"Switching from manual source installs to brew bottles; leftovers from a previous tool manager that used different markers; a stale symlink pointing outside the Cellar; another keg owns a shared directory.","solutions":["Remove or rename the listed conflicting files/symlinks yourself","Re-run `mise bootstrap packages apply`","If a conflicting symlink points into another Cellar keg, uninstall or relink that keg first","Verify ownership before deleting system-wide files"],"exampleFix":"# before\nls -l /home/linuxbrew/.linuxbrew/bin/tool  # foreign symlink\nrm /home/linuxbrew/.linuxbrew/bin/tool\n# after\nmise bootstrap packages apply","handlingStrategy":"validation","validationCode":"const conflicts = kegPaths.filter(p => fs.existsSync(p) && !createdByMiseOrBrew(p));\nif (conflicts.length) console.error('remove or rename:', conflicts);","typeGuard":null,"tryCatchPattern":"catch (e) {\n  if (String(e).startsWith('cannot link')) {\n    const files = e.message.split('\\n').filter(l => l.startsWith('  ')).map(l => l.trim());\n    files.forEach(f => fs.renameSync(f, f + '.bak'));\n    return retryApply();\n  }\n  throw e;\n}","preventionTips":["Uninstall manually installed copies of tools before switching to brew via mise","Inspect <prefix>/bin for foreign symlinks before running packages apply","Use one package manager per tool"],"tags":["brew","symlink","file-conflict","link"],"backgroundTag":"file-already-exists","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}