Posts

Homebrew For Mac | How To Install And Use Homebrew

I thought I should mention the very easy Homebrew package installer for Mac OS X. I’ve found it quite simple to use and have not turned back since I blew away my MacPorts.

You can find Homebrew on gitub and you can find the recommended installation instructions there which are as follows.

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

This will download the “go” ruby script and execute it in one go. If you are unsure or just curious and can read ruby code, then you can see this script here.

In brief, this script changes permissions on various directories, downloads the Homebrew install files and installs them under /usr/local

Before I ran this install, I blew away my MacPorts installation using these instructions, which suggests the following…

sudo port -f uninstall installed

sudo rm -rf \
    /opt/local \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0 \
    ~/.macports

Since Apple does not touch /usr/local I cleaned that out too, since anything in there on my Mac would have been installed by MacPorts. Homebrew installs under /usr/local and I wanted it to be nice and clean. Doing this will depend on what you’ve been up to with your Mac.

Some key files that will be installed by the installer are

/usr/local/bin/brew

This script does all the magic of installing, uninstalling, listing installed packages, showing package information and other tasks.

/usr/local/Cellar/

This directory is where the files are installed for the packages you install. You can see some of the package directories I have installed on this machine.

$ ls -dF1 /usr/local/Cellar/*
/usr/local/Cellar/bash-completion/
/usr/local/Cellar/geos/
/usr/local/Cellar/git/
/usr/local/Cellar/mongodb/
/usr/local/Cellar/ossp-uuid/
/usr/local/Cellar/pidof/
/usr/local/Cellar/postgis/
/usr/local/Cellar/postgresql/
/usr/local/Cellar/proj/
/usr/local/Cellar/readline/
/usr/local/Cellar/wget/

Once, you’re installed you should be able to run brew install to install packages.

Packages are first downloaded to /Library/Caches/Homebrew/, so if you do uninstall and re-install, you will not have to re-download them a second time.

Here’s a dump of the files my cache directory.

ls -1 /Library/Caches/Homebrew/*
/Library/Caches/Homebrew/bash-completion-1.2.tar.bz2
/Library/Caches/Homebrew/geos-3.2.2.tar.bz2
/Library/Caches/Homebrew/git-1.7.3.2.tar.bz2
/Library/Caches/Homebrew/git-htmldocs-1.7.3.2.tar.bz2
/Library/Caches/Homebrew/git-manpages-1.7.3.2.tar.bz2
/Library/Caches/Homebrew/mongodb-1.6.3-x86_64.tgz
/Library/Caches/Homebrew/mysql-5.1.51.tar.gz
/Library/Caches/Homebrew/ossp-uuid-1.6.2.tar.gz
/Library/Caches/Homebrew/pidof-0.1.4.tar.gz
/Library/Caches/Homebrew/postgis-1.5.2.tar.gz
/Library/Caches/Homebrew/postgresql-9.0.1.tar.bz2
/Library/Caches/Homebrew/proj-4.7.0.tar.gz
/Library/Caches/Homebrew/proj-datumgrid-1.5.zip
/Library/Caches/Homebrew/readline-6.1.tar.gz
/Library/Caches/Homebrew/solr-1.4.1.tgz
/Library/Caches/Homebrew/wget-1.12.tar.bz2

I will demonstrate installing Mongodb, which is a “scalable, high-performance, open source, document-oriented database”. Think “NoSQL”.

brew install mongodb

Here’s the output

==> Downloading https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-1.6.3.tgz
######################################################################## 100.0%
==> Caveats
If this is your first install, automatically load on login with:
    cp /usr/local/Cellar/mongodb/1.6.3-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

If this is an upgrade and you already have the org.mongodb.mongod.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
    cp /usr/local/Cellar/mongodb/1.6.3-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

Or start it manually:
    mongod run --config /usr/local/Cellar/mongodb/1.6.3-x86_64/mongod.conf
==> Summary
/usr/local/Cellar/mongodb/1.6.3-x86_64: 16 files, 83M, built in 2 seconds

A command I really like is the info command.

brew info mongodb

It will give you all the information you need for a particular package for starting, stopping, restarting or other actions pertinent the service you installed. If will be similar to the information output when you first install a package. It’s good to know about this command so that you can always find the maintenance commands.

Here is an example of the info command for the postgresql package.

brew info postgresql
postgresql 9.0.1

https://www.postgresql.org/

Depends on: readline, ossp-uuid
/usr/local/Cellar/postgresql/9.0.1 (1229 files, 25M)

If builds of Postgresl 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:

https://github.com/mxcl/homebrew/issues/issue/2510

To build plpython against a specific Python, set PYTHON prior to brewing:
  PYTHON=/usr/local/bin/python  brew install postgresql
See:

https://www.postgresql.org/docs/9.0/static/install-procedure.html

If this is your first install, create a database with:
    initdb /usr/local/var/postgres

If this is your first install, automatically load on login with:
    cp /usr/local/Cellar/postgresql/9.0.1/org.postgresql.postgres.plist ~/Library/LaunchAgents
    launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist

If this is an upgrade and you already have the org.postgresql.postgres.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
    cp /usr/local/Cellar/postgresql/9.0.1/org.postgresql.postgres.plist ~/Library/LaunchAgents
    launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist

Or start manually with:
    pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

And stop with:
    pg_ctl -D /usr/local/var/postgres stop -s -m fast

If you want to install the postgres gem, including ARCHFLAGS is recommended:
    env ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

https://github.com/mxcl/homebrew/commits/master/Library/Formula/postgresql.rb

brew list will tell you which packages are installed.

brew help will give you the following

Usage: brew [-v|--version] [--prefix [formula]] [--cache [formula]]
            [--cellar [formula]] [--config] [--env] [--repository]
            [-h|--help] COMMAND [formula] ...

Principle Commands:
  install formula ... [--ignore-dependencies] [--HEAD]
  list [--unbrewed|--versions] [formula] ...
  search [/regex/] [substring]
  uninstall formula ...
  update

Other Commands:
  info formula [--github]
  options formula
  deps formula
  uses formula [--installed]
  home formula ...
  cleanup [formula]
  link formula ...
  unlink formula ...
  outdated
  missing
  prune
  doctor

Informational:
  --version
  --config
  --prefix [formula]
  --cache [formula]

Commands useful when contributing:
  create URL
  edit [formula]
  audit [formula]
  log formula
  install formula [-vd|-i]

For more information:
  man brew

To visit the Homebrew homepage type:
  brew home

I hope you find this quick intro to Homebrew helpful. Please leave a comment to question.

Comments

  1. Sukima

    Out of curiosity why do you use sudo for all your commands. The docs specifically explain why that is a bad idea. A simple one time `sudo chown -R $USER /usr/local` fixes that issue. This makes life so much easier. sudo opens up a lot of opportunities to really blow things up. Your putting complete trust that there isn’t a bug or mistake in the hundreds of formula scripts. And entering in a password every time you use the brew command is a hassle.

  2. Jasper

    Stumbled across your post and because of that I read about homebrew… Just wanted to say thanks a lot! I was struggling like hell to get postgis working… and it works flawlessly now :)

  3. texnic

    Upon doing the ruby command, I’m getting

    curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

    Though you have -k in the keys already. Any idea of what I could try? I’ve Mac OS 10.5.8.

    1. Ulops

      Exactly the same issue. Also using 10.5.8

  4. Ramesh

    Hi,

    I have configured the brew in linux, How to make package for using brew ?

    Ramesh

  5. Ramesh

    Hi,

    I have installed brew in my linux (slackware13.1 linux)

    While run the command given below

    brew create https://ftp.acc.umu.se/pub/gnome/sources/libsoup/2.33/libsoup-2.33.90.tar.gz

    and typed the formula

    require ‘formula’

    class Libsoup Downloading https://ftp.acc.umu.se/pub/gnome/sources/libsoup/2.33/libsoup-2.33.90.tar.gz
    ######################################################################## 100.0%
    Warning: Cannot verify package integrity
    The formula did not provide a download checksum
    For your reference the MD5 is: f905e685f4e2fa6b414522e06d8db3c8
    /usr/bin/mktemp: cannot make temp dir /tmp/homebrew-libsoup-2.33.90-XXXX: Invalid argument
    Error: Couldn’t create build sandbox
    [email protected]:/tmp/brew/homebrew#

    I am getting above error. Please help me how to fix this error

    Ramesh

  6. Kyle

    Hello,

    I’ve just started using Homebrew and I love it. The only issue I am having is that it doesnt seem to be installing the man pages for any packages I install. I there something I need to alter somewhere or a flag I need to set?

    Thanks,
    Kyle

  7. Ramesh

    Hi Kyle,

    Thanks for your reply,

    Please let me know, how can you configure in your system in details…

    Ramesh

  8. JM

    What are the implications of changing all those permissions on system directories? This strikes me as an unwise decision, particularly changing the group id’s

  9. Paul

    Looks handy, but unfortunately the gist url for the installer script is now a 404

  10. Paul

    I found out that gist site has been restructured a little

    The ruby installer script can now be installed using…

    ruby -e “$(curl -fsSLk https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)“

  11. Josh Kosmala

    Hey Dude,

    Nice article. Here is the latest Ruby link if you want to update the link in your article.

    /usr/bin/ruby -e “$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)“

  12. Nuno Pimenta

    Hello,

    I’m trying to install package freerdp with homebrew;

    I did the following steps:

    1- Download Xcode 4.3.2 with command line tools
    2- Download homebrew;
    3- Execute command brew doctor to verify is everything is OK (give Warning: Unbrewed dylibs were found in /usr/local/lib, If you didn’t put them there on purpose they could cause problems when
    building Homebrew formulae, and may need to be deleted.)
    4- Download freerdp, brew install freerdp;
    5- Execute sudo brew link freerdp (Error: Cowardly refusing to `sudo brew link’
    You can use brew with sudo, but only if the brew executable is owned by root.)
    6- Execute brew link freerdp and its fine;

    How can i execute now freerdp and configure it?

  13. Nuno Pimenta

    Hello Phil,

    Thanks for the replay…

    Yesterday i run the command brew info freerdp, but didn’t return value information:
    gab-03:~ macbook$ brew info freerdp
    freerdp: stable 1.0.1, HEAD
    https://www.freerdp.com/
    Depends on: cmake, pkg-config
    /usr/local/Cellar/freerdp/1.0.1 (131 files, 2,1M) *
    https://github.com/mxcl/homebrew/commits/master/Library/Formula/freerdp.rb
    gab-03:~ macbook$

    Then, in the terminal.app, i navigate to the local were the packages are instaled, /usr/local/Cellar/freerdp/1.0.1/bin and i execute ./xfreerdp to see the resultes:
    gab-03:bin macbook$ ./xfreerdp
    missing server name
    failed to parse arguments.
    gab-03:bin macbook$

    That’s fine, because i didn’t configure anything. My point is how to configure now freerdp to make a connection to the server?

    I have another question, i execute brew doctor, and i have the results:
    Warning: Unbrewed dylibs were found in /usr/local/lib.
    If you didn’t put them there on purpose they could cause problems when
    building Homebrew formulae, and may need to be deleted

    Unexpected dylibs:

    /usr/local/lib/libgps.dylib /usr/local/lib/libpteiddlg.1.21.0.dylib /usr/local/lib/libpteidhttps.1.21.0.dylib /usr/local/lib/libpteidlib.1.21.0.dylib /usr/local/lib/libpteidlibopensc.1.21.0.dylib /usr/local/lib/pteidpkcs11.1.21.0.dylib

    I didn’t put anything there, i must remove the files????

    Thank you very much for the replay.
    Greatings from Portugal.

  14. Nuno Pimenta

    Hello everyone,

    I’m using freerdp on my Mac Mini, installed with homebrew.

    My system is OK, i can access to my Windows Server 2003 R2 with no problem, keyboard and mouse are working good.

    I use digital sign to all operations, but, the software for doing it can’t be installed in MAC. With the software, i use a smartcard reader, SCR3310, to reader my card.

    I need that freerdp permits using smartcard on my RDP session for digital sign, not for autentication. I can do this in a Windows XP because de RDP software permits using smart cards in the RDP session and my Windows Server 2003 R2 acept this.

    I did a little web resource and i am using the following command xfreerdp -u -g –plugin rdpdr –data scard:scard — and i can acess to my server but the server don’t recognizes the smart card reader.

    In the terminal.app, i get the following message:
    gab-03:bin macbook$ xfreerdp -u -g 1024*768 –plugin rdpdr –data scard:scard —
    loading plugin rdpdr
    freerdp_load_library_symbol: failed to open /usr/local/Cellar/freerdp/1.0.1/lib/freerdp/rdpdr: dlopen(/usr/local/Cellar/freerdp/1.0.1/lib/freerdp/rdpdr, 5): image not found
    freerdp_load_plugin: failed to load rdpdr/VirtualChannelEntry

    Can anyone point me any solution?

    Best regards

  15. franc

    All links to install homebrew are 404.
    Is this site dead?

    frank

  16. Stephen McConnell

    ruby -e “$(curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)”
    curl: (22) The requested URL returned error: 404

    The URL in the example returns a 404. I cut and pasted it. Didn’t work. But the rest of the tutorial was excellent.

    Thanks

    1. franc

      On the website:

      https://mxcl.github.com/homebrew/

      the command:

      ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”

      is working. There are more informations on:

      https://github.com/mxcl/homebrew/wiki/Installation

      it worked for me just some days ago, I could isntall FreeRDP (xfreerdp) with homebrew.

      frank

  17. Ann

    When I pasted it at the terminal prompt, I got:

    Failed during: Error: /usr/bin/xcode-select returned unexpected error. init -q

    Could you please help?

  18. Mark Scarton

    Hi, I’m new to MacOS (long time Unix and Linux user) and am running the latest update of Mountain Lion. I’d really like to use homebrew to gain access to my GNU tools. But when I attempt to run the script that you provided, I am receiving the following error:

    ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”
    -e:1: Invalid char `\342′ in expression
    -e:1: Invalid char `\200′ in expression
    -e:1: Invalid char `\234′ in expression

    Do you have any suggestions for what I might be doing wrong?

  19. Ranjna

    I am using mountain lion and was able to install homebrew, however, when i try installing any software using brew, I get Curl (7):failed to connect to 0.9.0.4: No route to host.

    I checked my firewall and it is not on. I even tried changing the url to use that really works in the rb file, but still get the same error. Any idea?

  20. Michael Stoneham

    I am trying to find a list of what the apps are in Homebrew. and not just a list but an explanation of what the apps are and do.

    also i want to let you know that i found a gui for Homebrew https://github.com/vincentsaluzzo/Homebrew-GUI/downloads which is easy to install and use. this gui would rock if it had descriptions for the apps built in.