可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
While installing tig
, HomeBrew
is displaying the following issues while installing a dependency:
Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/a2x /usr/local/bin is not writable. You can try again using: brew link asciidoc
回答1:
Following Alex' answer I was able to resolve this issue; seems this to be an issue non specific to the packages being installed but of the permissions of homebrew
folders.
sudo chown -R `whoami`:admin /usr/local/bin
For some packages, you may also need to do this to /usr/local/share
.
sudo chown -R `whoami`:admin /usr/local/share
回答2:
Rather than running any particular command, I would recommend running brew doctor
and taking all warnings seriously. There may be other problems you get stuck at which may not be captured in this question.
Also, as brew gets updated with time, particular commands may or may not remain valid. brew doctor
, however, will ensure that you get up to date troubleshooting.
回答3:
The other answers are correct, as far as they go, but they don't answer why this issue might be occurring, and how to address that root cause.
Cause
There are two possible causes to this issue:
- The homebrew installation was performed with a user other than the one you are currently using. Homebrew expects that only the user that installed it originally would ever want to use it.
- You installed some software that writes to /usr/local without using brew. This is the cause
brew doctor
suggests, if you run it.
Solution
Multiuser Homebrew
If you have multiple user accounts, and you want more than one of them to be able to use brew, you need to run through a few steps, otherwise you will constantly have to change ownership of the Homebrew file structure every time you switch users, and that's not a great idea.
Detailed instructions can be found online, but the quick answer is this:
Create a group named brew:
- Open System preferences
- Click Accounts
- Click the "+" (unlock first if necessary)
- Under New account select Group
- enter brew
- Click Create Group
- Select the brew group, and add the user accounts you want to use brew to it.
- change the /usr/local folder group ownership:
sudo chgrp -R brew /usr/local
- change the permissions to add write to /usr/local as group:
sudo chmod -R g+w /usr/local
- change homebrew cache directory group:
sudo chgrp -R brew /Library/Caches/Homebrew
- change the homebrew cache directory permissions:
sudo chmod -R g+w /Library/Caches/Homebrew
Single User Homebrew
If you're not trying to use more than one user with Homebrew, then the solution provided by the other answers, based on the suggestions of brew doctor
is probably sufficient:
sudo chown -R $(whoami) /usr/local
sudo chown -R $(whoami) /Library/Caches/Homebrew
Verification
After these steps, brew doctor
should report success by any user in the brew group, assuming you've logged out and back in to apply the new group memberships (if you went the multiuser route). If you just corrected things for single user homebrew, then logging out and back in shouldn't be necessary as none of your group memberships have changed.
回答4:
I found for my particular setup the following commands worked
brew doctor
And then that showed me where my errors were, and then this slightly different command from the comment above.
sudo chown -R $(whoami) /usr/local/opt
回答5:
For those who are looking for /usr/local/sbin
is not writable error:
UPDATE: It could be /usr/local/someOtherFolderName
e.g /usr/local/include
. You just need to create that folder with:
sudo mkdir someOtherFolderName
First create the sbin
folder, note that this requires sudo
privileges
回答6:
For me the solution was to run brew update
.
So, DO THIS FIRST.
This might be normal practice for people familiar with homebrew, but I'm not one of those people.
Edit: I discovered that I needed to update by running brew doctor
as suggested by @kinnth's answer to this same question.
A general troubleshooting workflow might look like this: 1. run brew update
2. if that doesn't help run brew doctor
and follow its directions 3. if that doesn't help check stack overflow
回答7:
This is because the current user is not permitted to write in that path. So, to change r/w (read/write) permissions you can either use 1. terminal, or 2. Graphical "Get Info" window.
1. Using Terminal
Google how to use chmod/chown (change mode/change owner) commands from terminal
2. Using graphical 'Get Info'
You can right click on the folder/file you want to change permissions of, then open Get Info which will show you a window like below at the bottom of which you can easily change r/w permissions: 
Remember to change the permission back to "read only" after your temporary work, if possible
回答8:
I've found the following relevant for Sophos Anti-Virus users:
https://stackoverflow.com/a/32981184
https://community.sophos.com/products/free-antivirus-tools-for-desktops/f/17/t/10029
In short, Sophos is changing permissions of certain /usr/local directories. Sophos has patched this and the fix is included with version 9.4.1.
回答9:
While doing brew link node In addition I got the following issues as well:
Error: Could not symlink include/node /usr/local/include is not writable.
Linking /usr/local/Cellar/node/9.3.0... Error: Permission denied @ dir_s_mkdir - /usr/local/lib
To solve the above just go to /usr/local/ and check the availability of folders 'include' and 'lib', if those folders are not available just create them manually.
And run brew install node again
回答10:
If you go to the folder in finder, right click and select "Get Info" you can go to the "Sharing and Permissions" section for the folder and allow "Read & Write" to "everyone"
This is what I do to make symlinks pass with this error. Also brew seems to reset the permissions on the folder also as if you hadn't altered anything