Homebrew is the most popular package manager for macOS. As the official documentation says, using the manager is the easiest and most flexible way to install the UNIX utilities that Apple didn’t include with macOS.

Assuming Homebrew is installed following commands install, remove and upgrade packages:

  • Install packages
$ brew install elixir
==> Downloading https://homebrew.bintray.com/bottles/elixir-1.4.2.el_capitan.bottle.tar.gz
Already downloaded: /Users/jakub/Library/Caches/Homebrew/elixir-1.4.2.el_capitan.bottle.tar.gz
==> Pouring elixir-1.4.2.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/elixir/1.4.2: 388 files, 5.5MB
  • Remove packages
$ brew remove elixir
Uninstalling /usr/local/Cellar/elixir/1.4.2... (388 files, 5.5MB)
  • Remove old versions of installed packages
$ brew cleanup
Removing: /usr/local/Cellar/ansible/2.2.1.0_1... (11,274 files, 120.6MB)
Removing: /usr/local/Cellar/awscli/1.11.55... (3,780 files, 32.7MB)
emoving: /Users/jakub/Library/Caches/Homebrew/awscli-1.11.63.el_capitan.bottle.tar.gz... (6.2MB)
Removing: /Users/jakub/Library/Caches/Homebrew/awscli-1.11.66.el_capitan.bottle.tar.gz... (6.2MB)
Removing: /Users/jakub/Library/Caches/Homebrew/erlang-19.2.3.el_capitan.bottle.tar.gz... (81.4MB)
Removing: /Users/jakub/Library/Logs/Homebrew/heroku... (108B)
[. . .]
Removing: /Users/jakub/Library/Logs/Homebrew/python3... (3 files, 115.5KB)
==> This operation has freed approximately 2GB of disk space.
  • Try to install already installed package
$ brew install elixir
Warning: elixir-1.4.2 already installed
  • List installed packages
$ brew list
[. . .]
git			    libassuan		libyaml			pkg-config		ssh-copy-id
  • Check what updates are available:
$ brew update
Updated 2 taps (caskroom/cask, homebrew/core).
==> New Formulae
alexjs            conjure-up        exa               httpflow          jvm-mon           libetpan          shfmt             terraform-docs    write-good
==> Updated Formulae
amazon-ecs-cli          dbhash                  gitbucket               latex2html              netpbm                  ragel                   strongswan
[. . .]
crystax-ndk             git-lfs                 kobalt                  mongodb                 pyenv ✔                 ssh-copy-id ✔
==> Deleted Formulae
android-ndk                 android-platform-tools      android-sdk                 dwarf-fortress              fb-adb                      multirust
  • Upgrade packages
$ brew upgrade
==> Upgrading 8 outdated packages, with result:
awscli 1.11.70, kubernetes-cli 1.6.0, node 7.8.0, pyenv 1.0.10, sqlite 3.18.0, ssh-copy-id 7.5p1, terraform 0.9.2, vim 8.0.0531
==> Upgrading awscli
==> Downloading https://homebrew.bintray.com/bottles/awscli-1.11.70.el_capitan.bottle.tar.gz
[. . .]

To speed up the process of upgrading and cleaning up packages set up the alias:

$ alias brewupdate='brew update && brew upgrade && brew cleanup; brew doctor'

To preserve the alias add it to the ~/.profile or ~/.bash_profile file.