Mac系统报错“No such keg: /usr/local/Cellar/imagemagick”如何解决?
Let's break down how to resolve this issue completely, since you've already started installing imagemagick@6 but hit the truncated keg-only prompt.
What's going on here?
The initial error means your system can't locate an ImageMagick installation in /usr/local/Cellar/imagemagick—either it was never installed, or it was removed. When you installed imagemagick@6, Homebrew marked it as keg-only because it's an alternate version of the main imagemagick formula (which defaults to v7.x these days). This means it won't automatically create symlinks in /usr/local/bin (where your system looks for commands) to avoid conflicts with the newer default version.
Complete Step-by-Step Fix
Confirm the installation status
First, verify thatimagemagick@6installed correctly by running:brew info imagemagick@6You’ll see output showing its installation path (usually
/usr/local/Cellar/imagemagick@6/6.9.9-38) and full details about the keg-only restriction.Add the keg-only version to your system PATH
This is the safest way to useimagemagick@6without breaking other tools. Depending on your shell:- For Bash users:
Open your~/.bash_profileor~/.bashrcfile in a text editor, then add this line:
Save the file, then apply the changes immediately:export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"source ~/.bash_profile - For Zsh users:
Open your~/.zshrcfile, add the sameexport PATHline above, then run:source ~/.zshrc
- For Bash users:
Verify the fix works
Test if your system can now find theimagemagick@6commands by running:convert --versionYou should see output showing version 6.9.9-38 (or the specific version you installed) instead of an error.
Optional: Force symlink (not recommended)
If you absolutely need imagemagick@6 to be your default ImageMagick version (and don’t mind overriding the main imagemagick symlinks), you can run:
brew link imagemagick@6 --force
⚠️ Warning: This will replace symlinks for the default imagemagick formula, which might break tools that expect version 7.x. Use this only if you’re sure you don’t need the newer version.
内容的提问来源于stack exchange,提问作者user2012677

