You just really need to understand a few basic concepts:
- Never run brew as sudo. Not "sudo brew install" nor "sudo brew link".
- The "Cellar" is a place that all your "kegs". Homebrew installs packages to their own directory (in the Cellar) and then symlinks their files into /usr/local/.
- Change /usr/local/* to be owned by $USER, not root, so you can have write permissions and not need sudo.
- The $PATH entry for /usr/local/bin should occur before /usr/bin.
$ sudo chown -R $USER /usr/local/* $ brew doctor $ brew update $ brew install python --with-brewed-openssl $ ls /usr/local/Cellar/python 2.7.6 $ python >>> 2.7.5Wait, I expected to see python 2.7.6 now. What happened?
$ which python /usr/bin/pythonBut the Homebrew docs said we will be using a symlink from /usr/local/bin/ that points at the Cellar instead of using /usr/bin:
$ ls -l /usr/local/bin/python lrwxr-xr-x 1 rkulla admin 33 Mar 2 06:37 /usr/local/bin/python -> ../Cellar/python/2.7.6/bin/pythonAha. So it must be a PATH issue:
$ echo PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin $ cat /etc/paths /usr/bin /bin /usr/sbin /sbin /usr/local/binWhen using Homebrew, we actually now want to change the position of /usr/local/bin to be before /usr/bin in $PATH. But don't edit /etc/paths. Instead edit ~/.bashrc and prepend /usr/local/bin to $PATH, like:
$ source ~/.bashrc $ echo $PATH $ /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/binDon't worry that there's duplicate entries for /usr/local/bin. It doesn't matter. What matters is that you've modified your PATH safely and ultimately cleaner than the other ways.
$ ls -l $(which python) lrwxr-xr-x 1 rkulla admin 33 Mar 2 06:37 /usr/local/bin/python -> ../Cellar/python/2.7.6/bin/pythonYay! And if you ever want to use the old python you can just run: /usr/bin/python.
Best of all from now on whenever you need to install anything with brew, you can just run:
$ brew install whateverand not have to fumble with permissions or worry about overwriting any global system files.
I also like to source ~/.bashrc from ~/.bash_profile. For why see: .bash_profile vs .bashrc