Beneath the pretty user interface, OS X is also an Unix. However, OS X lacks a system package manager like APT for Debian and Ubuntu, YUM for Fedora and CentOS and ports for FreeBSD; this situations makes installing source-based software inconvenient. Thanks to Homebrew, OS X has its own package manager now.
Since Homebrew build and installs software from source, we need a C/C++ compiler here. Get GCC compiler and other tools in Command Line Tools for Xcode at Apple Developer site. Besides, Xquartz is also needed for some X11 applications under OS X. iTerm 2 is not absolutely needed but recommended for better command line experiences.
After install the above software, you can install Homebrew. To install Homebrew, just paste or type the following command in terminal and press Return key:
Homebrew is installed in /usr/local, so you should edit PATH variable, adding /usr/local/bin and /usr/local/sbin in ~/.profile:
Homebrew wraps its action in a simple command called
brew. After installation of Homebrew, you should check the system environment. To check the environment, type
brew doctor in terminal:
Try to fix the warnings by
brew doctor as much as possible. The principle is that you should keep /usr/local and its subdirectories for Homebrew only and installing other software in other location like /opt.
To update the local repository, type
brew update. You should update the repo in the first use each day.
You can begin to install software after the above two steps. To search software, type
brew search package in terminal. Take vim as an example, you can find out vim, macvim and other packages. You can choose between Vim and MacVim.
To see available options for building package and other information about the chosen package, type
brew info package. With the same Vim example:
Since Homebrew is source-based, you have to compile the software from source. Traditional, we need three steps to install software in Unix are:
You do not need to know the details but basic awareness to the process help you to use Homebrew.
./configure generates proper Makefile for later use;
make compiles software from source;
make install installs software to proper location. Homebrew manages dependencies for you; therefore, you only need to choose among possible options. If you do not know which options are needed, you may also just accept default options.
Then, install software with
brew install package. Say we want to install Vim with Perl support. Homebrew will install all dependent software and libraries automatically.
To uninstall package, type
brew uninstall package.
To see more usage message of Homebrew, type
brew help or
man brew in terminal.