Decided to Switch to Homebrew
I've got an old install of Erlang, and Clojure, and I need to update them for work I'm about to do, but I don't feel like doing the same old installs… I'm going to try Homebrew for package management because it's working so well for my work laptop. So I cleared out the old installs of these packages, which was a chore - basically, complete directories in /usr/local/ or in ~/Library/ and I also took the time to clean up my .bash_login and .bashrc because they had additions for the PATH, and even DYLD_LIBRARY_PATH that needed to be removed as well.
Once I had the old stuff removed, I installed Homebrew with the simple command:
$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
and it installed itself just fine. Having done this already, I knew what to expect, but the next steps were really nice:
$ brew install erlang $ brew install leiningen
where Leiningen is the Clojure package manager and REPL tool. Once I had this installed, I noticed that /usr/local/bin wasn't early enough in my PATH to make sure that I picked off the Homebrew commands and not the native OS X commands.
Actually, Homebrew itself, pointed this out to me. Nice installer. So I had to track down where this was happening. Interestingly enough, I wasn't adding /usr/local/bin/ to my path - the system was! In /etc/paths there's a list of paths to add:
/usr/bin /bin /usr/sbin /sbin /usr/local/bin
and I needed to change it to:
/usr/local/bin /usr/bin /bin /usr/sbin /sbin
to get things right. Now, I had the PATH right, and both Erlang (erl) and Clojure (lein repl) started up just fine. Sounds like a no-op, but I'm on more recent versions, and for the work I'm about to get into, switching to Leiningen is a must.
But I didn't stop there… Oh no… I kept on cleaning things up. I don't even have Qt on this box, but that was in my PATH, and the Groovy, and a lot of other things that I don't have and don't need. All cleaned up.
By now my .bash_login and .bashrc are looking almost spartan. But then I was wondering about PostgreSQL. Was that on Homebrew? Would it work with Apache2 on my OS X box? Since I had the time, I decided to try it. So once again, I followed the simple steps to migrate from one package to the other:
Step 1 - make a complete backup. I went into my home directory and backed up everything in my server:
$ /usr/local/pgsql/bin/pg_dumpall -U _postgres -o > pgbackup
Step 2 - shut down the old version, and remove it's startup script from the system-wide install location:
$ sudo launchctl unload \ /Library/LaunchDaemons/org.postgresql.postgres.plist $ sudo rm /Library/LaunchDaemons/org.postgresql.postgres.plist
Step 3 - remove the old install and all the symlinks in the man pages and the /usr/local/bin directory that I did myself with this install:
$ cd /usr/local $ sudo rm -rf pgsql-9.1
there was some shell magic in the removal of the links - like an ls piped into a grep for 'pgsql' and then removing them. Nothing fancy, but it took a little time.
Now that the old PostgreSQL install was really gone - even from my .bash_login and .bashrc, I was ready to install the PostgreSQL from Homebrew. One of the reasons was that it was 9.2.1 and the previous install was 9.1.
Step 4 - install PostgreSQL:
$ brew install postgresql
Step 5 - create initial database for Homebrew PostgreSQL install:
$ initdb /usr/local/var/postgres -E utf8
Step 6 - set it to start on my login, and start it now:
$ mkdir -p ~/Library/LaunchAgents $ cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist \ ~/Library/LaunchAgents/ $ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Step 7 - reload databases from initial dump:
$ psql -d template1 -f ~/pgbackup
At this point, we can run psql and access the databases, and I'm sure I'm up and running, I needed to see about the integration with Apache2 - I have to have that working for some projects I've done, and are still working on.
Step 8 - activating PHP in Apache2 config on my box. Edit the file: /etc/apache2/httpd.conf and uncomment the line that looks like:
LoadModule php5_module libexec/apache2/libphp5.so
and restart apache:
$ sudo apachectl graceful
Step 9 - make my ~/Sites directory executable again. Create the file /etc/apache2/users/drbob.conf:
<Directory "/Users/drbob/Sites/"> Options FollowSymLinks Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
and at this point, I had the quite familiar PHP info screen up and my simple database accessing page worked like a charm. I'd successfully completed the migration!
But was I done? No!
I've been running boost 1.49.0 for a while, and I like that I figured out how to do universal binaries of the libraries. Very nice. But then I checked Homebrew:
$ brew info boost boost: stable 1.52.0 (bottled), HEAD www.boost.org Not installed github.com/mxcl/homebrew/commits/master/Library/Formula/boost.rb ==> Options --with-icu Build regexp engine with icu support --without-python Build without Python --with-mpi Enable MPI support --universal Build a universal binary
so I could update to boost 1.52.0 and get the same universal binaries without missing a beat! This might be really nice. So I removed my own boost install:
$ cd /usr/local/include $ sudo rm -rf boost $ cd /usr/local/lib $ sudo rm -rf libboost_*
and then I installed boost from Homebrew:
$ brew install boost --universal
Odd… I got:
...failed updating 22 targets... ...skipped 12 targets... ...updated 10743 targets... READ THIS: github.com/mxcl/homebrew/wiki/troubleshooting These open issues may also help: github.com/mxcl/homebrew/issues/14749
The hint was to run brew doctor and correct all the errors. Well… I had a lot of them - all from my manual boost and gfortran installs. So I ditched my old gfortran install and cleaned up all the problems and then I re-ran the install:
/usr/local/Cellar/boost/1.52.0: 9086 files, 362M, built in 6.1 minutes
When I looked in /usr/local/include and /usr/local/lib I see all the boost code, and I even checked that I got the universal binaries:
$ file /usr/local/lib/libboost_wave-mt.dylib /usr/local/lib/libboost_wave-mt.dylib: Mach-O universal binary with 2 architectures /usr/local/lib/libboost_wave-mt.dylib (for architecture i386): Mach-O dynamically linked shared library i386 /usr/local/lib/libboost_wave-mt.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
Excellent!
Now to put back gfortran from Homebrew:
$ brew install gfortran
and after cleaning up more cruft from the old gfortran install, it installed and worked just fine!
I have now successfully removed all the third-party builds I once used with Homebrew. This is amazing stuff.