Wilson Mar bio photo

Wilson Mar

Hello. Hire me!

Email me Calendar Skype call 310 320-7878

LinkedIn Twitter Gitter Google+ Youtube

Github Stackoverflow Pinterest

Packaged for easy digestion


Overview

This tutorial provides a deep dive of Homebrew, a package manager for Mac OSX (MacOS) like Chocolatey for Windows, apt-get for dpkg, or yum for RPM.

Step-by-step instructions are provided here to install Homebrew itself and then install Homebrew packages based on the name of formulae specified for installation in a command such as:

brew install wget

DEFINITION: A formula provides instructions on how to install packages and their dependencies, such as where to find tar.gzip files for download.

Brew installs packages in its own Cellar directory (folder) and adds symlinks to the /usr/local folder.

About Homebrew

Homebrew is the newest and most popular package utility on OSX.

Its web page is at http://brew.sh

Alternatives to Homebrew:

  • https://www.macports.org/

sudo port install tree

  • http://www.finkproject.org/

Preparations

  1. Make a full backup of your system before following these instructions.

  2. Install XCode.

    If XCode is not already installed, you are prompted to install it.

    Homebrew requires OS X 10.5+ and the Xcode command line tools.

    Since the El Capitan version of Mac OSX, file permissions in /usr/local have changed, causing error messages such as:

    The linking step did not complete successfully
    The formula built, but is not symlinked into /usr/local
    
  3. So in a Terminal shell window at any folder:

    sudo chown -R :staff /usr/local

Install Homebrew

  1. Install Homebrew if you haven’t already.

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

    CAUTION: Don’t press Enter on the Terminal until the Download Software dialog reaches 100%.

    Press the Enter key to the message:
    Press RETURN to continue or any other key to abort. then

    To proceed, enter the root password, or type Ctrl+C to abort.

    NOTE: The download is from
    https://github.com/Homebrew/homebrew/

    HISTORICAL NOTE: Previously, the Homebrew installer was at
    https://raw.github.com/Homebrew/homebrew/go/install/

  2. Identify where the Homebrew program itself is located:

    
    which brew
    

    The response:

    /usr/local/bin/brew
    

    The “brew” above is a shell script file.

    Update Homebrew itself

  3. Get Homebrew version:

    
    brew -v
    

    The response (at time of writing) indicates Homebrew is not “v1.0” yet:

    Homebrew 0.9.9 (git revision e9cc; last commit 2016-06-12)
    Homebrew/homebrew-core (git revision 3977; last commit 2016-06-12)
    

    NOTE: Homebrew is open-sourced at
    https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Common-Issues.md

  4. To update Homebrew itself and its formulas:

    brew update
    brew update

    Yes, run it twice to make sure all dependencies took.

    Each run can take several minutes.

Formulas

### Search for a formula to install #

  1. Use an internet browser (such as Google Chrome) to view formula defined in

    Install formula

  2. Install the wget command-line utility by formula name (for example, wget):

    brew install wget

    This installs to folder /usr/local/bin/wget.

    See Tips & Tricks on how to use proxy, remove the beer mug emoji, highlighting within editors, etc.

    How many?

  3. Get a count of kegs, how many files, and the disk space they take:

    brew info –all

    A sample response:

    15 kegs, 18,528 files, 540.6M
    

    Where did it go?

  4. List where .tar.gz “bottle” files are downloaded into from the internet:

    DEFINITION: A “Bottle” is a pre-built binary Keg used for installation instead of building from source. It can be unpacked.

    brew –cache

    The response includes your user name, which enables Homebrew to work without using sudo (elevation to root).

    /Users/mac/Library/Caches/Homebrew
    

    The equivalent of the above is:

    ~/Library/Caches/Homebrew
    
  5. List bottles downloaded:

    ls ~/Library/Caches/Homebrew
    

    Examples of responses:

    autoconf-2.69.el_capitan.bottle.4.tar.gz	
    maven-3.3.9.tar.gz
    awscli-1.10.44.el_capitan.bottle.tar.gz
    node-6.2.2.tar.xz
    docker-1.11.2.el_capitan.bottle.tar.gz
    openssl-1.0.2h_1.el_capitan.bottle.tar.gz
    gimp-2.8.16-x86_64.dmg
    pkg-config-0.29.1.el_capitan.bottle.tar.gz
    libgpg-error-1.23.el_capitan.bottle.tar.gz
    readline-6.3.8.el_capitan.bottle.tar.gz
    libksba-1.3.4.el_capitan.bottle.tar.gz
    
  6. List brew formulas installed:

    ls /usr/local/Cellar
    brew list
    brew ls

    The alternative commands above all do the same thing of the same folder, for example:

    autoconf	awscli		libgpg-error	libtool		maven		node		pkg-config	xz
    automake	docker		libksba		libyaml		mysql		openssl		readline
    

    There is no response if no brew package has been installed.

  7. See one level below one of the above folders for a specific formula, such as openssl:

    
    ls /usr/local/Cellar/openssl/
    

    It is usually a version number, such as:

    1.0.2h_1
    

    DEFINITION: A “Keg” is the installation prefix of a formula, such as:

    openssl-1.0.2h_1.el_capitan.bottle.tar.gz
    

    Packages

  8. List brew package .rb (Ruby language) files installed:

    ls /usr/local/Library/Taps/homebrew/homebrew-core/Formula
    

    The response is a long list.

  9. List brew package folders:

    brew search

    The response is a long list.

Troubleshoot Homebrew

  1. Different ways to install weget.

    The above is one of several ways to install the wget command-line utility.

    One way is to install Apple’s Xcode.

    brew install –build-from-source wget

    Test wget operating:

    cd ~/Downloads
    wget http://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz

  2. Verify brew installation:

    brew doctor

    If you see this message at the top of messages returned:

    Warning: Unbrewed header files were found in /usr/local/include.
    If you didn't put them there on purpose they could cause problems when
    building Homebrew formulae, and may need to be deleted.
    

    The above may occur if curl and nodejs were installed without using homebrew.

    Remove them before installing node and curl using Homebrew:

    
    rm -rf /usr/local/include/node/
    
  3. Create symlinks to installations performed manually in Cellar. This allows you to have the flexibility to install things on your own but still have those participate as dependencies in homebrew formulas.

    First, see what exactly will be overwritten, without actually doing it:

    brew link –overwrite –dry-run openssl

    The response is:

    Warning: openssl is keg-only and must be linked with --force
    Note that doing so can interfere with building software.
    

    “Keg-only” refers to a formula installed only into the Cellar and not linked into /usr/local, which means most tools will not find it. This is to avoid conflicting with the system version of the same package.

    Alternately, if aswcli is specified for dry-run, the response is:

    Warning: Already linked: /usr/local/Cellar/awscli/1.10.44
    To relink: brew unlink awscli && brew link awscli
    

    brew link

    NOTE: Homebrew installs to the Cellar it then symlinks some of the installation into /usr/local so that other programs can see what’s going on.

    A symlink to the active version of a Keg is called an “opt prefix”.

    If you see this message:

    Warning: Broken symlinks were found. Remove them with `brew prune`:
    
    
    brew prune
    

    A sample response:

    Pruned 1598 symbolic links and 185 directories from /usr/local
    
  4. List formula (package definitions):

    brew edit $FORMULA

    The above command brings you to your default text editor (vim or whatever is specified in the $EDITOR variable).

    Type :q to quit out.

Upgrade brew formulas

  1. List brew packages that are obsolete:

    brew outdated

    To stop a specific package from being updated/upgraded, pin it:

    brew pin $FORMULA

    $FORMULA is ???

    To allow that formulae to update again, unpin it.

  2. Download and update ALL software packages installed:

    brew upgrade

  3. To see which files would be removed as no longer needed:

    brew cleanup -n

    No response if there is nothing to clearn.

  4. To really remove all files no longer needed:

    brew cleanup

    A sample response:

    Removing: /Users/mac/Library/Caches/Homebrew/mariadb-10.1.14.el_capitan.bottle.tar.gz... (36.6M)
    ==> This operation has freed approximately 36.6M of disk space.
    

Tap

Brew tap adds repos not in the Homebrew master repo from inside a larger package.

https://github.com/Homebrew/brew/blob/master/docs/brew-tap.md says tap adds to the list of formulae that brew tracks, updates, and installs from.

  1. List brew tap packages already installed:

    brew tap
    
  2. Install the ip tool included with iproute2 on Linux:

    brew tap brona/iproute2mac
    brew install iproute2mac
    

    The command specififies the account and repo in GitHub, as in
    https://github.com/brona/iproute2mac

    or https://superuser.com/questions/687310/ip-command-in-mac-os-x-terminal

    ifconfig en0 | grep inet | grep -v inet6 | cut -d ' ' -f2
    
  3. Try it (instead of ifconfig):

    ip
    ip addr show en0
    
  4. Remove a tap:

    brew untap brona/iproute2mac
    

Brew Cask Install

Homebrew cask extends homebrew and brings its elegance, simplicity, and speed to MacOS (OS X) GUI applications and large binaries.

With Cask, you can skip the long URLs, the “To install, drag this icon…”, and manually deleting installer files.

  1. Install brew cask:

    
    brew tap caskroom/cask
    brew install brew-cask
    

    Applications are kept in their Caskroom under /opt and symblinked to $HOME/Applications.

  2. https://caskroom.github.io, the home page, said there are 3,197 casks as of June 5, 2016.

    QUESTION: Is there a graph of growth in cask counts over time?

  3. Install the cask extension to Homebrew:

    
    brew tap caskroom/cask
    

    Alternately:

    
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null
    
  4. Search for a cask by name, in website is where casks are obtained:

    https://github.com/caskroom/homebrew-cask/search?utf8=✓

    Alternately, run a search command. This example searches for “yo”:

    
    brew cask search yo
    

    PROTIP: One should see the cask definition before using it. I would be suspicious of casks with sparse information.

    The safe way to get the homepage URL of the programmer is from here (don’t Google it and end up at a rogue site).

  5. Look at some cask definitions:

    https://github.com/caskroom/homebrew-cask/blob/master/Casks/google-chrome.rb is a sample cask definition:

cask 'google-chrome' do
  version :latest
  sha256 :no_check

  url 'https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg'
  name 'Google Chrome'
  homepage 'https://www.google.com/chrome/'
  license :gratis

  auto_updates true

  app 'Google Chrome.app'

  zap delete: [
                '~/Library/Application Support/Google/Chrome',
                '~/Library/Caches/Google/Chrome',
                '~/Library/Caches/com.google.Chrome',
                '~/Library/Caches/com.google.Chrome.helper.EH',
                '~/Library/Caches/com.google.Keystone.Agent',
                '~/Library/Caches/com.google.SoftwareUpdate',
                '~/Library/Google/GoogleSoftwareUpdate',
                '~/Library/Logs/GoogleSoftwareUpdateAgent.log',
              ],
      rmdir:  [
                '~/Library/Caches/Google',
                '~/Library/Google',
              ]
end
  1. Install the cask:

    brew cask install google-chrome

    Cask downloads then moves the app to the ~/Applications folder, so it can be opened this way:

  2. Open the installed cask from Terminal:

    
    open /Applications/"Google Chrome.app"
    
  3. Installing with cask enables you to cleanup:

    
    brew cask cleanup
    

Debian apt-get

Download Fink commander Fink Installer.pkg from
http://finkcommander.sourceforge.net/help/install.php

This explains: Fink stores data in the directory “/sw” by default. This goes against the Filesystem Hierarchy Standard’s recommendation to use “/usr/local”. Within Fink’s directory, a FHS-like layout (/sw/bin, /sw/include, /sw/lib, etc.) is used.

Documentation

  1. For more documentation on brew, look here and:

    man brew

Social media

Social media from brew’s readme:

More on OSX

This is one of a series on Mac OSX: