Installed, just not linked

Note: I'm not so good at using shell.

I was trying to install Valgrind using brew on Yosemite.

brew install --HEAD valgrind

Towards the end, I got an error having to do with linking so when I tried to reinstall, I got:

Warning: valgrind-HEAD already installed, it's just not linked

So apparently I've already installed it. Then based on other SO questions and answers, I tried:

brew link valgrind

This seemed to solve other people's problems with linking an already installed software but this gave me an error:

Linking /usr/local/Cellar/valgrind/HEAD... 
Error: Could not symlink lib/pkgconfig/valgrind.pc
/usr/local/lib/pkgconfig is not writable.

I also tried to update brew but it didn't solve the issue. If it is not writable, maybe sudo would give me permission but I don't want to use sudo without knowing exactly what I am doing.

What is happening and how to I fix it?


Looks like a permission issue. I would try doing this

chmod 755 /usr/local/lib/pkgconfig

This should make that available, then try

brew link valgrind

If that doesn't work I would try doing a check on it

brew doctor

First run

brew link <package>

If it gives an error, try for an automated diagnosis

brew doctor

brew doctor gives a list of problems that could be leading to errors in installation process.

To fix problems in case of conflicting files, run to get a list of all actions which will be performed by overwrite without actually performing them.

To list all files that would be deleted:

  brew link --overwrite --dry-run <package>

followed by this run which will execute the overwrite, assuming you feel that the actions performed by overwrite will take your system to a more stable state.

To force the link and overwrite all conflicting files:

 brew link --overwrite <package>

If none of above the solution works, try this.

sudo chown -R $USER:admin /usr/local
brew link <package-name>