You keep seeing the word "Homebrew" whenever you install an app that isn't simply dragged into the Applications folder. What is Homebrew? The site says "package manager," but what's a package manager? What's a package? What's a manager? There, there - no need to pull your hair out. We'll go over all of this and more in today's tutorial.
What is Homebrew?
Homebrew is a package manager for OS X, we've covered that much. But what is it actually, in layman terms? To explain that, we need to cover the idea of "packages".
Packages are bundles of source code distributed by developers of software, which can be compiled and installed on your machine. They are little more than archives (not unlike zip) packed with various files. So why not refer to them as archives? Well, packages have the specific feature of being what one might call "installable".
Packages are installable bundles of source code.
When you download a bundle of source code manually, you typically have to unarchive (expand) it, then go into the folder this process produced, run several cryptic commands (make, configure), and finally, with a whole lot of luck, the software gets installed.
This will often fail if you don't meet some prerequisites. For example, you have the wrong OS version or you don't have some pre-installed packages that the package you're trying to install depends on (these are called dependencies). You can actually see this cryptic and seemingly complex procedure in a previous article on installing PHP from source code.
An example of such software would be Imagemagick. Imagemagick is a library and command-line tool for image manipulation. In layman terms, it's a set of programs that help you edit pictures in various ways by typing out commands in your Terminal application.
Saying it's a "library" actually means that it can be used by other programs - which means you can initiate Imagemagick commands from other languages such as Java, PHP, etc., by installing additional upgrades to those languages.
A library is a set of files that can be used by other applications and programming languages to achieve the same effect via various means.
Installing this library is actually quite straightforward. Simply download the installer binary (executable file) and run it. Unfortunately, keeping the software up to date is less simple, and after installing dozens of such and similar libraries, it's easy to lose track of where what was placed, thus clogging up your hard drive. This is where package managers come in.
A package manager is an application that handles all the above for you with one simple command. Up until recently, MacPorts was the package manager of choice for OS X, followed closely by Fink. I won't be going into comparisons of these managers here, and if you're interested in knowing more you can Google around for articles such as this one.
What Does a Package Manager Do?
What does a package manager do, exactly? The premise is simple:
- Takes a single command as input and figures out which software package you want installed
- Downloads the source code of the package (or in Fink's case, the pre-built application itself)
- Figures out if any dependencies are present and if so, downloads them as well
- Compiles (builds) the dependencies from the source code files and installs them
- Builds your requested software
- Installs it into the predefined location
A package manager such as Homebrew automatically handles all dependencies and installs requested software into one common location for easy access and updating.
Thus, installing the aforementioned Imagemagick with Homebrew becomes as simple as running
brew install imagemagick.
Homebrew Installation and Specifics
To install Homebrew, all you have to do is run your Terminal app (Applications > Utilities > Homebrew) and run the following command:
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
There's no need to bake your noodle over what this means, all you need to know is that it installs the package manager and prepares it for use.
If we now run
brew doctor, Homebrew will self-diagnose, see if everything works the way it should and report back. It will usually tell you what's wrong in great detail, so that you can help it fix itself very quickly, on the off chance something goes wrong.
Brew Doctor is Homebrew's own self-diagnosis tool.
Once this is done, you should run
brew update in order to download new "formulae".
Running Brew Update
Formulae are instructions for Homebrew on how to install specific software and where to find the necessary files and dependencies. For example, one such formula is the imagemagick formula which contains the location of Imagemagick source files, a list of all dependencies, instruction on how and where to install which files and how to update the application. Homebrew keeps these instructions and updates them every time you run
brew update in order to always provide you with the most recent "recipes". However, it is important to note that "update" only updates Homebrew itself - it won't upgrade the software. If you wish to upgrade specific software, the "upgrade" command needs to be used.
brew update is for updating Homebrew, brew upgrade is for updating installed software
Should the Imagemagick suite be updated later on, all you need to do is run
brew upgrade imagemagick. To upgrade all outdated installed formulae, you can simply run
brew upgrade, which automatically checks the entire "Cellar" (the folder into which all Homebrew-fetched software is installed) for outdated installations and replaces them with newer versions.
If you wish to uninstall a formula because you feel like you no longer need it or you seem to be running dangerously low on disk space, there's the
brew uninstall [formula] command where [formula] should be replaced by the formula name, e.g.
brew uninstall imagemagick.
To see a list of most of the available formulae, see this, but keep in mind that there are other "taps" out there - custom made ones that have formulae not hosted on the main Homebrew repository, and as such might have to be added specifically to become available, but offer some useful software once they are. One such example is Jose Gonzales' PHP-related brew repository which enables you to install PHP with Homebrew, thus avoiding some of the needless complexity of the aforementioned PHP post.
You can read details on this specific repo at its website, but one other command I'd like to mention is the "tap":
brew tap [repo] where [repo] is replaced by the repository name, like so:
brew tap josegonzalez/homebrew-php. The tap command "opens a tap", that is, allows Homebrew to read another repository of formulae. This then expands your options of installable software.
You now know what Homebrew is and does. There are plenty more commands to discover, but those are irrelevant at this point seeing as those who need them already usually know about them. What matters is that you now know how to install and update Terminal-installed software with a single line of input. I hope this article alleviated some of the fear and mystique around Homebrew, and I hope you'll try it out and discover some new and interesting software through it.
As always, thank you for reading, and if you have any questions please post in the comments and I'll do my best to reply as soon possible. Would you like to learn more about a certain Mac related topic or part of OS X that confuses or scares you? Please post that too, and we'll do our best to cover it as soon as possible.
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!Translate this post