Short Homebrew tutorial

This is a very short tutorial about using Homebrew, the package manager for modern MacOS systems.

You can find more info HERE on the official documentation.

 

INSTALL HOMEBREW

To install Homebrew open Launchpad --> Terminal, paste into it the following command and hit return
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Follow the onscreen instructions and you'll have homebrew installed.

At the end run the commmand
brew update

This will update the program list

Let's start by expanding the repository list in order to include more software. This doesn't install any software so it is safe for any user. Run the following commands in sequence (line by line):
brew tap "caskroom/cask"
brew tap "caskroom/drivers"
brew tap "caskroom/fonts"
brew tap "caskroom/versions"
brew tap "homebrew/bundle"
brew tap "homebrew/core"
brew tap "homebrew/science"

 

HOMEBREW USAGE

First things first, you need to familiarize yourself with some of the basic homebrew commands. Some terminology: Homebrew uses things called "formulae" as recipes to install applications.You won't need to edit or change them, just know they exists. Homebrew is easily extensible to include many package sources, through the "tap" subcommand. Homebrew has a "cask" subcommand which will allow you to install packages directly from the cask repository. This repository has a large selection of commonly used programs already packaged as pre-build MacOS apps. Of course to use homebrew you have to use the command line interface... I'll sum up few useful Homebrew commands, however for more info consult google or run "man brew" in a terminal.

All commands start with the binary:
brew

If you want to search for a program, you must invoke "brew search", e.g.
brew search gcc
will return:
apple-gcc42  gcc ✔        [email protected]      [email protected]      [email protected]      [email protected]      gcc@5

Caskroom/cask/gcc-arm-embedded

In my case gcc is installed so a symbol "✔" is next to it. In this case you have more versions of the same program, the default one (gcc) and other possible versions (e.g. [email protected] if you want that specific version instead of the latest one). If you want more info on a specific entry use the following command:
brew info gcc

 will return a lot of informations:
gcc: stable 6.3.0 (bottled), HEAD
GNU compiler collection
https://gcc.gnu.org/
/usr/local/Cellar/gcc/6.3.0_1 (1,436 files, 273.2MB) *
  Poured from bottle on 2017-01-05 at 15:27:35
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gcc.rb
==> Dependencies
Required: gmp ✔, libmpc ✔, mpfr ✔, isl ✔
==> Options
--with-all-languages
    Enable all compilers and languages, except Ada
--with-java
    Build the gcj compiler
--with-jit
    Build the jit compiler
--with-nls
    Build with native language support (localization)
--without-fortran
    Build without the gfortran compiler
--without-multilib
    Build without multilib support
--HEAD
    Install HEAD version
==> Caveats
GCC has been built with multilib support. Notably, OpenMP may not work:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60670
If you need OpenMP support you may want to
  brew reinstall gcc --without-multilib

If you want to install it just run:
brew install gcc

Or if you want to enable some specific option listend in the info screen above, e.g. without multilib support, run:
brew install gcc --without-multilib

If you don't find the package you are searching you can try also the cask repository (where most pre-built apps are found). Homebrew-Cask extends Homebrew simplyfiying the installation and management of GUI macOS applications. E.G. firefox has a pre-built app and you don't find it in the regular search. You will find it here:
brew cask search firefox

==> Exact Match
firefox ✔
==> Partial Matches
firefox-beta                  firefoxdeveloperedition       multifirefox
firefox-esr                   firefoxnightly

You can see that multiple firefox versions are available through the "cask" repository. To have more info on cask packages run:
brew cask info firefox

while to install them you can just run:
brew cask install firefox

To update and upgrade the packages that you installed throught Homebrew repository, please run the following command:
brew update; brew upgrade; brew cleanup

For convenience you can just create an alias in your .bash_profile file by adding the following line:
alias brewup="brew update; brew upgrade; brew cleanup"

If you did, running "brewup" in a terminal will execute all the above commands.

 

CONFIGURE GITHUB ACCESS

Hombrew uses a github repository for its lists of formulae and casks. If you sync too often, it will ban you for some time unless you use a registered account.

  1. Go to Github and sign up for a new account. It will require a mail address and will ask con confirmation by sending you an email.
  2. Once you are registered login to your account (Sign in). Click on the icon on the right of the top bar and select "Settings".
  3. On the left column select what should be the last item "Personal access tokens", then click on "Generate new token"
  4. Select a token description (anything, like "homebrew") and deselect every checkbox. On the bottom of the page click "Generate token".
  5. Copy the alphanumeric string that will appear in the window (E.G. 98a753f53034f6979d63c9525d54f75d347973e4).
  6. Edit your .bash_profile and add the following line:
    export HOMEBREW_GITHUB_API_TOKEN="98a753f53034f6979d63c9525d54f75d347973e4"
    Substitute the string 98a753f53034f6979d63c9525d54f75d347973e4 with the string that you copied at step 5.
  7. Now you will never be temporary banned anymore!