jdx/mise · error
cannot link : these files already exist and were not…
Error message
cannot link {name}: these files already exist and were not created by mise or brew:
{}
Remove or rename them, then re-run `mise bootstrap packages apply` What it means
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.
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
Example fix
# before ls -la /usr/local/bin/foo # your own old script # after mv /usr/local/bin/foo /usr/local/bin/foo.bak mise bootstrap packages apply
Defensive patterns
Strategy: validation
Validate before calling
for f in bin/foo lib/libfoo.dylib; do p="$(brew --prefix)/$f" [ ! -e "$p" ] && continue owner=$(stat -c '%U' "$p") echo "conflict: $p (owned by $owner)" done
Try / catch
try {
applyBrewPackage(name);
} catch (e) {
if (String(e).includes('these files already exist')) {
// parse listed paths, move them aside, then re-run
moveConflictsAside(e);
applyBrewPackage(name);
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- app Info.plist must be a regular file
- app target is outside an allowed Applications directory
- artifact target has changed
- binary target is not an owned Caskroom symlink
- brew bottles are only published for a formula's current…
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/85fe2573bfc55570.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/packages/brew/pour.rs:789
let linked = prefix::linked_keg_record(name);
if can_overwrite(&linked) {
links.push((linked, keg.clone()));
} else {
conflicts.push(linked);
}
}
if can_overwrite(&opt_link) {
// Create opt last: keg_installed uses it as the completion marker, so a
// process killed during public linking cannot make a partial pour look
// complete to another process waiting on the commit lock.
links.push((opt_link.clone(), keg.clone()));
} else {
conflicts.push(opt_link);
}
if !conflicts.is_empty() {
// nothing has been linked yet, and the caller rolls the keg back on
// this error — so don't claim it remains usable
bail!(
"cannot link {name}: these files already exist and were not created by mise or brew:\n{}\n\
Remove or rename them, then re-run `mise bootstrap packages apply`",
conflicts
.iter()
.map(|p| format!(" {}", p.display()))
.collect::<Vec<_>>()
.join("\n"),
);
}
// remember every symlink we overwrite (upgrades replace the previous
// version's links, opt included) so a failed link restores all of them
let mut created: Vec<PathBuf> = vec![];
let mut replaced: Vec<(PathBuf, PathBuf)> = vec![];
let mut failure: Option<eyre::Report> = None;
for (dest, target) in &links {
let made = (|| -> Result<()> {
// a parent that is a brew directory symlink must become a real
// directory first — otherwise the link below would be createdView on GitHub (pinned to 533346cc37)