For some reason since the El Capitan upgrade the /usr/local/bin and /usr/local/share directories are not owned by the current logged in user. This means that Homebrew is not able to access these locations and add the files it needs to install software for you on OS X.

To fix this you will need to use chown in the Terminal application to reclaim permissions for these directories. Open up a terminal and run:

sudo chown -R `whoami`:admin /usr/local/bin

You will be prompted for your password when using the sudo command.

Then run:

sudo chown -R `whoami`:admin /usr/local/share

Now you can rerun your brew install command.

Note: If you have already installed the homebrew package, you will simply need to link it instead. If you see an error similar to:

brew install the_silver_searcher
Warning: the_silver_searcher-0.31.0 already installed, it's just not linked

Then simply run:

brew link the_silver_searcher

Do you run Sophos Antivirus?

I have heard that currently there is a problem with Sophos on El Capitan. When its scans your computer it will touch the /usr/local/ directory and affect the permissions. Sophos are working on a fix for this but currently you may discover permission problems even without a log out or system reboot.