From Segfault
Jump to navigation Jump to search


If no Xcode is installed (and no GUI is available), we may have to install the Xcode command line utitilies manually:

xcode-select --install


Homebrew likes to install to /usr/local[1], but one can specify any other directory:[2]

curl -OL https://raw.githubusercontent.com/Homebrew/install/master/install.sh

Adjust the install file:

HOMEBREW_PREFIX = '/opt/homebrew'
abort <<-EOABORT unless `groups`.split.include? "staff"

Execute the install script:

$ ruby ./install
==> This script will install:

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown sue /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/bin/chgrp admin /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 461, done.
remote: Compressing objects: 100% (419/419), done.
remote: Total 461 (delta 28), reused 292 (delta 17), pack-reused 0
Receiving objects: 100% (461/461), 761.55 KiB | 573.00 KiB/s, done.
Resolving deltas: 100% (28/28), done.
From https://github.com/Homebrew/brew
 * [new branch]      master     -> origin/master
HEAD is now at 36b2af2 superenv: fix formula prefix path to consider revisions
==> Tapping homebrew/core
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 3660, done.
remote: Compressing objects: 100% (3545/3545), done.
remote: Total 3660 (delta 17), reused 446 (delta 3), pack-reused 0
Receiving objects: 100% (3660/3660), 2.75 MiB | 1.62 MiB/s, done.
Resolving deltas: 100% (17/17), done.
Checking connectivity... done.
Tapped 3535 formulae (3,686 files, 8.6M)
Warning: /opt/homebrew/bin is not in your PATH.
==> Installation successful!
==> Next steps
Run `brew help` to get started

Optionally lock down the installation directory:

sudo chown -R homebrew:homebrew /opt/homebrew/                        # Create a user first!

Adjust your PATH variable accordingly:

export PATH=$PATH:/opt/homebrew/bin


We may need special sudo rules for our homebrew user:

%staff  ALL=(homebrew:homebrew) NOPASSWD: /opt/homebrew/bin/brew
homebrew ALL=(ALL) NOPASSWD:SETENV: /usr/sbin/installer
  • This will allow all members of the staff group to execute brew as the user homebrew w/o providing a password.
  • The user homebrew may call the installer w/o providing a password, since we didn't set one. Also, the homebrew user will be allowed to preserve the environment.[3] The latter may be required for some bundles (e.g. VirtualBox).


Also, some brew bundles may want to create symlinks in /usr/bin/local and will fail when the homebrew user is not allowed to do so. Let's use ACLs to allow that:

sudo chmod +a "homebrew allow read,execute,add_file,delete_child" /usr/local/bin

Now we should have something like this:

$ ls -lde /usr/local/bin
drwxr-xr-x+ 30 root  wheel  1020 May 15 12:41 /usr/local/bin
0: user:homebrew allow list,add_file,search,delete_child


List available packages:

$ brew search | wc -l

Update brew itself and all formulae:

$ sudo -H -u homebrew brew update
Updated Homebrew from 3dc4841 to cfef282.
Updated 2 taps (caskroom/cask, homebrew/versions).

Upgrade all packages:

sudo -H -u homebrew brew upgrade --cleanup

If the sudo calling is too cumbersome, try an alias:

$ alias brew="sudo -H -u homebrew /opt/homebrew/bin/brew"
$ set -x
$ brew update
+ sudo -H -u homebrew /opt/homebrew/bin/brew update
Already up-to-date.

Brew Bundle

  1. brew tap adds more GitHub repos to the list of available formulae.
  2. Homebrew Cask can be used to install (native) Mac applications.

Let's combine[4] them:

brew tap Homebrew/bundle

Now "brew bundle should work. We can use a Brewfile to list all the applications to install:

$ cat .Brewfile.local
cask_args appdir: '/Applications/BrewBundle'
# cask 'adium'
# cask 'audacity'
# cask 'burn'
# cask 'citrix-receiver'
# cask 'handbrake'
cask 'firefox'
# cask 'flux'
# cask 'google-chrome'
# cask 'libreoffice'
# cask 'microsoft-lync'
# cask 'osxfuse'
# cask 'picasa'
# cask 'skype'
# cask 'sshfs'
# cask 'steam'
# cask 'sqlitebrowser'
# cask 'soundflower'
# cask 'teamviewer'
cask 'thunderbird'
# cask 'tunnelblick'
cask 'virtualbox'
# cask 'vlc'

$ sudo mkdir -m 0755 -p /Applications/BrewBundle /opt/homebrew-cask
$ sudo chown homebrew:homebrew /Applications/BrewBundle /opt/homebrew-cask

Try to use the 'Brewfile now:

$ brew bundle --file=$HOME/.Brewfile.local
Succeeded in installing firefox
Succeeded in installing thunderbird
Succeeded in installing virtualbox
Success: 3 Fail: 0

We need to use Homebrew Cask to list the installed packages:

$ brew cask list
firefox      thunderbird  virtualbox


Upgrade all casks[5], as this isn't possible yet:[6][7]

brew cask list | xargs brew cask install --force

This doesn't work of course when Homebrew is installed as a different user. As xargs(1) doesn't recognize aliases[8], we may have to use a wrapper script after all:

$ cat /usr/local/bin/brew.sh
sudo -H -u homebrew /usr/local/bin/brew $@

$ (brew.sh cask list | xargs brew.sh cask install --force) 2>&1 | tee ~/.log/brew-cask-upgrade.log


Before reporting bugs, one could try to reset the Homebrew installation:

brew doctor

Annoying bugs, that were closed w/o a fix:


Uninstall Homebrew[9]:

curl -O https://raw.githubusercontent.com/Homebrew/install/master/uninstall
ruby ./uninstall