{"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":789,"sourceCode":"        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 can_overwrite(&opt_link) {\n        // Create opt last: keg_installed uses it as the completion marker, so a\n        // process killed during public linking cannot make a partial pour look\n        // complete to another process waiting on the commit lock.\n        links.push((opt_link.clone(), keg.clone()));\n    } else {\n        conflicts.push(opt_link);\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":771,"sourceCodeEnd":807,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/pour.rs#L771-L807","documentation":"Linking a keg into the brew prefix (symlinking bin/lib/share etc. into the filesystem) only proceeds when every destination path is absent or owned by mise/brew. If files or directories already exist at link targets that neither tool created, link_keg refuses, listing the conflicts, because overwriting foreign files could destroy unrelated data. The keg is rolled back, so nothing is left half-linked.","triggerScenarios":"link_keg (called from install_prepared and upgrade tests) encounters existing regular files/dirs at opt-link or KEG_LINK_DIRECTORIES targets that were not created by mise or brew — e.g. /usr/local/bin/foo already contains your own script where brew's prefix is /usr/local.","commonSituations":"Installing brew packages into /usr/local on macOS where other package managers or manual installs already placed binaries; leftover files from a removed tool; previously `cp`-installed equivalents of formula binaries.","solutions":["Remove or rename the listed conflicting files (the error lists each path), then re-run `mise bootstrap packages apply`","Check who owns the conflicting files (`ls -la <path>`) — if they belong to another package manager, uninstall via that manager instead of deleting blindly","Choose a different brew prefix (via MISE_SYSTEM_BREW_PREFIX) so mise's links don't collide with existing content"],"exampleFix":"# before\nls -la /usr/local/bin/foo   # your own old script\n# after\nmv /usr/local/bin/foo /usr/local/bin/foo.bak\nmise bootstrap packages apply","handlingStrategy":"validation","validationCode":"for f in bin/foo lib/libfoo.dylib; do\n  p=\"$(brew --prefix)/$f\"\n  [ ! -e \"$p\" ] && continue\n  owner=$(stat -c '%U' \"$p\")\n  echo \"conflict: $p (owned by $owner)\"\ndone","typeGuard":null,"tryCatchPattern":"try {\n  applyBrewPackage(name);\n} catch (e) {\n  if (String(e).includes('these files already exist')) {\n    // parse listed paths, move them aside, then re-run\n    moveConflictsAside(e);\n    applyBrewPackage(name);\n  } else throw e;\n}","preventionTips":["Don't hand-copy binaries into the brew prefix's bin/lib directories","Check for collisions (`mise bootstrap packages status`) before applying packages into a shared /usr/local prefix","Prefer a dedicated brew prefix (e.g. /home/linuxbrew/.linuxbrew) over /usr/local where other tools install files"],"tags":["brew","file-conflict","linking"],"backgroundTag":"file-already-exists","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}