This page has been updated on 2021-01-07 14:02

If you're coming from Linux, you know about dpkg, rpm, apt, yum or pacman and how easy it is to install a new application or feature on your computer, update and maintain it against bugs and security issues.

macOS don't provide such management tool, (actually it has installer(8) and softwareupdate(8) but those are not widely used) instead, users are invited to use the App Store and download software approved by Apple. You can still download software from publisher websites in the form of dmg or zip files from which you drag and drop the app to the Application folder. But at the first start, macOS might block it, suggesting that if it doesn't come from the App Store, it is dangerous. More about this at HT202491

Hopefully, there's a community driven project providing a package manager, and repos from where you can install virtually everything from command line tools like htop, tree, git, programming languages like Python, Go, Rust or Julia to the most popular OSS like Firefox, LibreOffice, Postgresql or Krita. This project is Homebrew.

Installation

The installation can be break down into three simple steps :

1 - Command line tools :

Then, if you don't have installed Xcode yet, you need at the command line tools :

xcode-select --install

Wait until the tools are downloaded (~ 450MB) and fully installed - you will be prompted for your user password.

2 - Install brew :

Then, go to the Homebrew web site and follow the instructions which were, at the time of the redaction :

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

3 - Disable Gatekeeper :

This step is optionnal and I do not recommend it

Allow apps from anywhere and prevent gatekeeper shouting at you every time you install a new package :

sudo spctl --master-disable

Verify by issuing spctl --status or open System Preferences and check the security & privacy settings :

gatekeeper

et voilà !

Basic usage

There are two types of packages : Formulaes and Casks. The first will install command line tools, the second are graphical applications you will run from the Application folder.

Exemple of a Formulae installation :

cold [ ~ ]$ brew install --formulae htop
==> Downloading https://homebrew.bintray.com/bottles/htop-3.0.4.catalina.bottle.tar.gz
Already downloaded: /Users/arthur/Library/Caches/Homebrew/downloads/23f37eb4677e0403e456d34b8dab9145de7560b90f38bc257fa9527df0f52b0b--htop-3.0.4.catalina.bottle.tar.gz
==> Pouring htop-3.0.4.catalina.bottle.tar.gz
==> Caveats
htop requires root privileges to correctly display all running processes,
so you will need to run `sudo htop`.
You should be certain that you trust any software you grant root privileges.
==> Summary
🍺  /usr/local/Cellar/htop/3.0.4: 12 files, 267.8KB

Example of a Cask installation :

cold [ ~ ]$ brew install --cask firefox
==> Downloading https://download-installer.cdn.mozilla.net/pub/firefox/releases/84.0.2/mac/en-US/Firefox%2084.0.2.dmg
######################################################################## 100.0%
==> Installing Cask firefox
==> Moving App 'Firefox.app' to '/Applications/Firefox.app'.
🍺  firefox was successfully installed!

To uninstall a package :

cold [ ~ ]$ brew uninstall --formulae htop
Uninstalling /usr/local/Cellar/htop/3.0.4... (12 files, 267.8KB)
cold [ ~ ]$

To update brew

cold [ ~ ]$ brew update
Updated 1 tap (homebrew/cask).
==> Updated Casks
canva

To upgrade all the packages :

cold [ ~ ]$ brew upgrade
==> Upgrading 1 outdated packages:
rust 1.48.0 -> 1.49.0
==> Upgrading rust 1.48.0 -> 1.49.0
==> Downloading https://homebrew.bintray.com/bottles/rust-1.49.0.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/79a71993f6bd900369575448730cc767a2dc6bf26783941f2144520f16806205?response
######################################################################## 100.0%
==> Pouring rust-1.49.0.catalina.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/rust/1.49.0: 14,553 files, 569.1MB
Removing: /usr/local/Cellar/rust/1.48.0... (14,251 files, 558.0MB)
Removing: /Users/arthur/Library/Caches/Homebrew/rust--1.48.0.catalina.bottle.tar.gz... (126.7MB)
cold [ ~ ]$

To list the installed packages :

cold [ ~ ]$ brew list --formulae
autoconf           ipcalc             nmap
automake           isl                openssl@1.1
bash-completion    jpeg               pcre2
boost              libmodplug         pkg-config
brogue             libmpc             python@3.9
cmake              libogg             ranger
coreutils          libpcap            readline
cowsay             libpng             rogue
discount           libssh2            rust
fortune            libtiff            sdl2
gcc                libtool            sdl2_image
gdbm               libvorbis          sdl2_mixer
gettext            lolcat             sqlite
gifsicle           make               tcl-tk
git                micro              tcpdump
gmp                mpfr               tree
go                 mtr                watch
htop               ncurses            webp
icu4c              nethacked          xz

cold [ ~ ]$ brew list --cask
caffeine           Julia              tigervnc-viewer
firefox            qlmarkdown         typora
gns3               rectangle

bash completion

Add to your ~/bashrc :

if type brew &>/dev/null; then
  HOMEBREW_PREFIX="$(brew --prefix)"
  if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
    source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
  else
    for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
      [[ -r "$COMPLETION" ]] && source "$COMPLETION"
    done
  fi
fi

Advanced usage

Formulaes are installed in /usr/local/cellar and binaries linked in /usr/local/bin

you can unlink a particular package using brew unlink

Using brew over a proxy :

Set the ftp_proxy, http_proxy, https_proxy environment vars to point to your proxy server. If they all point to the same proxy, you can set all_proxy instead.

brew leaves > my_brews.txt
xargs brew install < brew.txt

Conclusion

You already fell like at home don't you ?


Published

Last Updated

Category

Admin

Tags

Contact