Installing tmux but getting “dyld: Library not loaded Referenced from: /usr/”

dynamic libraryhomebrewinstalltmux

I try to do

brew install tmux

it installs, but, probably due to previous failed and not fully removed non-brew attempts to install both it and libevent, when try to use tmux I get

$ tmux
dyld: Library not loaded: /usr/local/lib/libevent-2.0.5.dylib
  Referenced from: /usr/local/bin/tmux
  Reason: image not found
Trace/BPT trap: 5

I tried to install libevent but I got:

$ brew install libevent
Warning: libevent-2.0.21 already installed, it's just not linked

so I tried

$ brew link libevent

but I got

Linking /usr/local/Cellar/libevent/2.0.21... 
Warning: Could not link libevent. Unlinking...
Error: Could not symlink file: /usr/local/Cellar/libevent/2.0.21/include/event2/util.h
Target /usr/local/include/event2/util.h already exists. You may need to delete it.
To force the link and overwrite all other conflicting files, do:
  brew link --overwrite formula_name
To list all files that would be deleted:
  brew link --overwrite --dry-run formula_name

so I tried

$ brew link --overwrite libevent

but I got

Linking /usr/local/Cellar/libevent/2.0.21... 
Warning: Could not link libevent. Unlinking...
Error: Permission denied - /usr/local/include/event2/util.h

so I tried

$ sudo brew link --overwrite libevent

Password:

but I got

Error: Cowardly refusing to `sudo brew link`
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.

I'm stuck.

Best Answer

Mine had the same problem.

$ tmux
dyld: Library not loaded: /usr/local/lib/libevent-2.0.5.dylib
Referenced from: /usr/local/Cellar/tmux/1.9a/bin/tmux
Reason: image not found
Trace/BPT trap: 5

Tried to install libevent but it was already there, not linked yet:

$ brew install libevent
Warning: libevent-2.0.21 already installed
$ brew link libevent
Warning: Already linked: /usr/local/Cellar/libevent/2.0.21
To relink: brew unlink libevent && brew link libevent

I solved it by doing exactly what was suggested above:

$ brew unlink libevent && brew link libevent
Unlinking /usr/local/Cellar/libevent/2.0.21... 4 links removed
Linking /usr/local/Cellar/libevent/2.0.21... 25 symlinks created
$ tmux -V
tmux 1.9a