72

When I try to install a library with homebrew (brew install aLibrary), I got the following error:

Could not symlink lib/pkgconfig/aFile
/usr/local/lib/pkgconfig is not writable.

What should I do?

There are several questions and answers (1,2,etc.) concerning this brew error, this is an attempt to make a general question as suggested here.

Community
  • 1
  • 1
arthur.sw
  • 11,052
  • 9
  • 47
  • 104

5 Answers5

167

As explained here by Rick:

Start with brew doctor which will show you errors with your brew setup.

You might see something like this: "Warning: /usr/local/lib/pkgconfig isn't writable."

It will give you the advice that: "You should probably chown /usr/local/lib/pkgconfig".

This means: sudo chown -R $(whoami) /usr/local/lib/pkgconfig

Then you will need to link the files with this: brew link yourLibrary

If this does not work hopefully the output of brew doctor will give you enough to continue the search.

Community
  • 1
  • 1
arthur.sw
  • 11,052
  • 9
  • 47
  • 104
  • 25
    `sudo chown -R $(whoami) /usr/local/lib/pkgconfig` seems a great copy paste answer. –  Dec 31 '15 at 13:57
  • I had 2 folders that needed this action. Running `brew doctor` and then copying the suggested command from there is even better. – Andrei Tudor Diaconu Apr 04 '18 at 10:48
  • But why does brew need access to something that it doesn't have by default? What is the purpose of that dir and why should i go out of my way to give extra access to brew? – xdhmoore Jul 03 '19 at 22:08
12

Giant Elk had a great suggestion and this is how I fixed my issue, which in my opinion is the cleanest. Users should not change permissions unless they know the ramifications.

  1. Output your installed packages (via brew) to a text file:

    brew list > brewlist.txt
    
  2. Uninstall brew:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
    
  3. Re-install brew:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  4. Re-install previous packages (edit list if you do not need all packages):

    brew install $(< brewlist.txt )
    
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
RSchroeder
  • 121
  • 1
  • 2
  • Am doing this now, and perhaps 2. and 3. could be updated since I got the messages: Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in Bash. Please migrate to the following command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" – horseshoe7 Apr 25 '21 at 07:41
  • and for uninstall: Warning: The Ruby Homebrew uninstaller is now deprecated and has been rewritten in Bash. Please migrate to the following command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" – horseshoe7 Apr 25 '21 at 07:42
  • Also, step 4 can very likely fail for one item, and then fails the whole thing. So I ended up having to install each one individually, which of course takes more time. – horseshoe7 Apr 25 '21 at 07:46
4

Use the following.

$ brew doctor

message will display error links to prune. If any found, run next option.

$ brew prune

once these are removed, proceed to link them agian

$ brew link python
Tunaki
  • 132,869
  • 46
  • 340
  • 423
3

I uninstalled brew, re-installed, then the issues went away.

Giant Elk
  • 5,375
  • 9
  • 43
  • 56
3

You should simply give the permission to your account by running this command on terminal.

sudo chown -R $(whoami) (path)

In your case: sudo chown -R $(whoami) lib/pkgconfig/aFile /usr/local/lib/pkgconfig

defcon
  • 123
  • 7