All posts

[Guide] Homebrew: package manager for MacOS

Homebrew Package Manager

Homebrew is a package manager for MacOS that lets you install new software in a very easy way. If you come from the Linux world, then you can think of homebrew as analogous to apt-get, yum, dnf, yaourt, etc.

I would say that Homebrew is a must for any Mac user and even more if you are a software developer.

Installing Homebrew

The installation is very easy, you just have to run the following command in the terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After installing it you should run brew doctor and check that everything is all right. If you don’t see any error message, then you are done.

Warning messages are not harmful

As you can see, there is a new command available: brew. This utility enables you to install and update packages in your system.

Basic usage

Each piece of software is installed using the so called formuale; they are just ruby files that indicate how to install each package in the system. The great thing about Homebrew is that it provides a DSL so anyone can create new formulae. Also, the system is very transparent, you can see how a package is going to be installed thorugh inspecting its formulae.

Install new packages

brew install <formulae>

~ ❯ brew install youtube-dl
==> Downloading https://github.com/rg3/youtube-dl/releases/download/2017.10.01/youtube-dl-2017.10.01.
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/1039520/57a48802
######################################################################## 100,0%
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/youtube-dl/2017.10.01: 11 files, 1.9MB, built in 8 seconds

Search packages

brew search <name>

~ ❯ brew search http
==> Searching local taps...
darkhttpd           httpdiff            httpry              libmicrohttpd       weighttp
http-parser         httperf             httpstat            lighttpd
http-server         httpflow            httptunnel          mighttpd2
http_load           httpie ✔            libhttpserver       nghttp2
...

It will show a checkmark (✔) if the formulae is already installed.

List installed packages

brew ls

~ ❯ brew ls
ack			exiftool		gmp			libevent		libyaml			neovim			python3			tree
atool			fontconfig		gobject-introspection	libffi			little-cms2		node			ranger			unibilium
...

Update the packages repository

brew update

You should do this quite often in order to keep the package’s database updated.

❯ brew update                                                           1s 582ms
Updated Homebrew from 5a2817cb to 714bf515.
Updated 6 taps (homebrew/core, caskroom/drivers, caskroom/fonts, caskroom/versions, caskroom/cask, caskroom/eid).
==> New Formulae
deark
==> Updated Formulae
boost ✔                    fuego                      openimageio
macvim ✔                   gegl                       osquery
...

Upgrade installed software

brew upgrade

It upgrades any installed package. You should probably run brew update beforehand.

❯ brew upgrade                                                         25s 457ms
==> Upgrading 41 outdated packages, with result:
syncthing 0.14.45 -> 0.14.46, vim 8.0.1553_2 -> 8.0.1700, neo4j 3.3.0 -> 3.3.4, libtiff 4.0.9_2 -> 4.0.9_3, pandoc 2.1.2 -> 2.1.3, cmake 3.10.2 -> 3.11.0, libuv 1.19.2 -> 1.20.0, python 3.6.4_4 -> 3.6.5, logstash 6.2.2 -> 6.2.3, boost 1.66.0 -> 1.67.0, icu4c 60.2 -> 61.1, neofetch 3.3.0 -> 3.4.0, glib 2.54.3 -> 2.56.1, sqlite 3.22.0 -> 3.23.1, libgpg-error 1.27 -> 1.29, gobject-introspection 1.54.1_1 -> 1.56.1, fribidi 1.0.1 -> 1.0.2, yarn 1.5.1_1 -> 1.6.0, mongodb 3.6.3 -> 3.6.4, lua 5.3.4_2 -> 5.3.4_3, htop 2.0.2_2 -> 2.2.0, geckodriver 0.19.1 -> 0.20.1, media-info 17.12 -> 18.03.1, translate-shell 0.9.6.6 -> 0.9.6.7, macvim 8.0-145_1 -> 8.0-146_1, unrar 5.6.1 -> 5.6.2, tmux 2.6 -> 2.7, oniguruma 6.7.1 -> 6.8.2, isl 0.18 -> 0.19, youtube-dl 2018.03.10 -> 2018.04.16, openssl@1.1 1.1.0g_1 -> 1.1.0h, pcre 8.41 -> 8.42, node 9.8.0 -> 9.11.1, nmap 7.60 -> 7.70, jq 1.5_2 -> 1.5_3, poppler 0.62.0 -> 0.63.0_1, openssl 1.0.2n -> 1.0.2o_1, imagemagick 7.0.7-26 -> 7.0.7-28, ruby 2.5.0_2 -> 2.5.1, git 2.16.2 -> 2.17.0, flow 0.67.1 -> 0.70.0
==> Upgrading openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.0h.high_sie
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.0h.high_sierra.bottle.tar.gz
...

Remove a package

brew uninstall <formulae>

Getting package’s information

brew info <formulae>

~ ❯ brew info youtube-dl
youtube-dl: stable 2017.10.01, HEAD
Download YouTube videos from the command-line
https://rg3.github.io/youtube-dl/
/usr/local/Cellar/youtube-dl/2017.10.01 (11 files, 1.9MB) *
  Built from source on 2017-10-01 at 18:41:49
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/youtube-dl.rb
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

Help

And of course it includes a help command: brew help [command]

~ ❯ brew help
Example usage:
brew search [TEXT|/REGEX/]
brew (info|home|options) [FORMULA...]
brew install FORMULA...
brew update
brew upgrade [FORMULA...]
brew uninstall FORMULA...
brew list [FORMULA...]
...

Official documentation

If you want to know more about Homebrew, you can check the official documentation and their FAQ section.

Discussion

Personally, I use Homebrew almost every day and I’m sure that anything I’d need as a developer can be found there. The most amazing thing for me is the way it works… if you look closely, it is based entirely on Git, plain Ruby DSL code and a defined process of user contributions through commits.