Install and Use Homebrew on macOS

Homebrew is a package manager for macOS. You can use Homebrew to install command line packages on a Mac, provided someone has written a formulae, which is a simple Ruby script that walks through the process for installing all the little bits required for a piece of software.

Installing Homebrew is simple. Run the following command which is listed on the Homebrew homepage (not as root):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
This will install the macOS Command Line Tools from Xcode as well as create the following directories (if they’re not already present):
  • /usr/local/Cellar
  • /usr/local/Homebrew
  • /usr/local/Frameworks
  • /usr/local/opt
  • /usr/local/sbin
  • /usr/local/share/zsh
  • /usr/local/share/zsh/site-functions
  • /usr/local/var
Then the script will move all the required bits from https://github.com/Homebrew/brew to the correct locations. Once done, you can easily install a package if you know the name. For example, I do this on practically every new machine I configure for development:

brew install wget

This one is nice because the dependencies that get installed. And you get the latest versions. Let’s look at the version for wget:

wget -V

Next, let’s use brew to search for something: radius

brew search radius

You’ll see that there’s one item on the local taps: freeradius-server

Let’s install that:

brew install freeradius-server
Now, you’ll find that the bits that make freeradius work are located in /usr/local/Cellar/freeradius-server/3.0.16. If you later need to upgrade that package, use the upgrade verb.

brew upgrade freeradius-server

And finally, to update Homebrew to the latest version, run the update verb:

brew update
  • epsiblivion

    you man want to mention that you need xcode cli tools installed. here is tim’s script to do it without gui prompts: https://github.com/timsutton/osx-vm-templates/blob/master/scripts/xcode-cli-tools.sh

    • Installing Homebrew will automatically install the CLI tools they (or Xcode) isn’t available. They use the same method that the above script uses, and it would also be better maintained because they’ll be getting bug reports whenever it breaks.

  • JS

    One thing that bugs me is that brew requires to be run as an Administrator user. I typically don’t want to run my everyday chores as one, so I write a little wrapper script:

    #! /bin/sh

    brew=/usr/local/bin/brew
    su=/usr/bin/su
    brewadmin=admin
    if sudo true ; then
    cd /tmp; umask 022
    if [ ! -x ${brew} ] ; then
    installbrew=/tmp/install-brew
    curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install > “${installbrew}”
    chmod 755 “$installbrew”
    sudo ${su} ${brewadmin} -c /tmp/install-brew
    fi
    sudo ${su} ${brewadmin} ${brew} $@
    fi

  • elwit

    Err, I got to this page from here: http://krypted.com/guides/migrating-services-macos-server/, by clicking on the link titled “Configure FreeRADIUS on MacOS”. Unfortunately, it seems to the the same content as the link to install FreeRadius.

    I’ve worked through the second version of the official Apple documentation (https://developer.apple.com/support/macos-server/macOS-Server-Service-Migration-Guide.pdf) on migrating Radius, which is awful. There are two obvious errors that have nothing to do with the actual configuration:

    – When building talloc, “configure -without-gettext” should be “configure –without-gettext”
    – When setting up the launchctl file, “sudo chmod root:wheel …” is clearly wrong, should be chown

    Needless to say, this reduced my confidence in the official apple guides instructions on how to configure FreeRadius. And sure enough, after following the guide, freeradius -XC shows no errors, but my firewall VPN that depends on radius authentication doesn’t work. I haven’t actually upgrade OS X server yet, so I’ve fallen back to that in the meantime.

    I don’t know if anyone else has successfully worked through the Apple docs. If there are instructions on how to configure the brew-built freeradius, I could probably switch to that.