brew安装软件报错:Error: Permission denied - /usr/local/opt/jpeg

时间:2023-01-05 17:53:15

在MacOS使用brew安装libjpeg,报没有权限:

$ brew install libjpeg
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/jpeg-8d.mountain_lion.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/jpeg-8d.mountain_lion.bottle.1.tar.gz
==> Pouring jpeg-8d.mountain_lion.bottle.1.tar.gz
Warning: Could not link jpeg. Unlinking...
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link jpeg'
Error: Permission denied - /usr/local/opt/jpeg

解决方法:

在MacOS High Sierra,/usr/local目录不能再使用chown。替代方案为:

sudo chown -R $(whoami) $(brew --prefix)/*

参考:https://github.com/Homebrew/brew/issues/3228