I've just taken proud ownership of a shiny new iMac which meant I had the (dis)pleasure of downloading all of my applications and setting up my development environment. I thought this would be the usual manual process but thanks to Homebrew and Homebrew Cask it was all be automated.
Homebrew is one of the first things I always chuck on a new Mac. Installing it is just a one-line command in the terminal.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
On first run it'll probably ask you to install Xcode's command line tools.
Homebrew allows us to install all the packages Apple missed out. For example, we're probably going to want to install OpenSSL, a version of PHP with MCrypt baked in, and some form of database system like MySQL or Postgres.
Once it's all installed we can run things like
brew install mysql to download, compile and install various packages.
For full documentation on Homebrew, check out their Github project.
To install it, run the following on your command line.
brew install caskroom/cask/brew-cask
Now we can run things like this:
brew cask install google-chrome
Basically any app that isn't reliant on the App Store and is remotely popular will be available as a formula for you to take advantage of.
You might want to run the commands with the --appdir flag as otherwise they'll be installed in
/opt/homebrew-cask/Caskroomand symlinked to your
Bundle, and the Brewfile
Homebrew is great but it could be quicker. Thankfully there's a package called Bundle that will allow us to use a Brewfile to run several of our homebrew commands in one go.
Of course we could just write a bash script to run the commands for us but the brewfile just feels a little more elegant to me.
A brewfile is very similar to Ruby's Gemfile that's used to manage dependencies and I guess it could also be compared to the
composer.json file in PHP.
We can install the Bundle package in by running another command in a terminal to fetch it for us.
brew install homebrew/boneyard/bundle
Once installed we can create our Brewfile! You can pop this anywhere you like, you'll just need to make sure you run the
brew bundle command later from the same directory.
Here's my completed Brewfile that I keep safely in my dotfiles repo:
# BREWWWWW # Install Dev bits and pieces tap josegonzalez/php tap homebrew/dupes install openssl install php56-mcrypt install josegonzalez/php/composer install mysql install phpunit install node install npm # Install Cask install caskroom/cask/brew-cask # Install Casks cask install virtualbox cask install vagrant cask install iterm2 cask install sequel-pro cask install the-unarchiver cask install google-chrome cask install atom cask install spotify
With Homebrew and the bundle pacakge installed I just clone my dotfiles repo down and run the
brew bundle command. It'll install all my essential tools like PHP and Node, grab Cask for me and then install my OS X apps with one single line.
I think that's pretty fucking awesome.
Once you've ditched Bash for ZSH you'll never want to go back (trust me, it's worth it for the autocomplete alone). Thankfully we can install it with one line thanks to Oh My ZSH
curl -L http://install.ohmyz.sh | sh
That's it! Everything will be ready for us and we can configure our
~/.zshrc file as required.
Happy coding 😊