Rocu.de

Love, caffeine and omlette

Manage your Mac Apps with homebrew-cask

A while ago I became interested in automating the setup of my Macs. I started my journey with chef-solo, however this wasn't really practical for me, so I switched to homesick to manage my dotfiles.

Unfortunately that left me without a solution to install my apps automatically.

Not any more. homebrew-cask to the rescue!

Take a walk

Image Source: Flickr/megoizzy (CC BY-SA 2.0)

What is homebrew-cask

homebrew-cask is a Homebrew extension that allows you to install your apps like this:

brew cask install evernote

How to install homebrew-cask

If you already use homebrew, installing homebrew-cask is really simple:

brew tap phinze/homebrew-cask
brew install brew-cask

If you have Alfred installed you should also configure it, so that it recognizes apps managed by homebrew-cask.

brew cask alfred link

Using homebrew-cask

Using homebrew-cask is simple. You install apps using the brew cask install command. Evernote for example, you would install like this:

brew cask install evernote

Create a little script to install your Apps

I store all my apps in a file called ~/.brew. In order to install the apps I just have to run it.

This is how you create your own:

touch ~/.brew
chmod +x ~/.brew

Now fill it with the Apps you want to install across all your Mac's.

For me this looks like:

#!/bin/bash
brew cask install google-chrome  
…
brew cask install rubymine  
brew cask install charles  
brew cask install mou  
brew cask install bit-torrent-sync  

I have this file on GitHub and symlink it with homesick. When I am on a new Mac I just have to run

~/.brew

That installs all my common apps.

Create own casks

There are over 300 casks available already. You can view a list with

brew cask search

If your favorite app is missing it is really simple to add it.

In the example below I create a Cask for Soulver.

brew cask create soulver

An editor opens with the newly generated cask.

class Soulver < Cask  
   url ''
   homepage ''
   version ''
   sha1 ''
   link ''
end  

You just have to fill in the download URL of the app, the apps name, the version, the sha1 checksum of the download and it's homepage.

class Soulver < Cask  
  url 'http://www.acqualia.com/files/download.php?product=soulver'
  homepage 'http://www.acqualia.com/soulver/'
  version 'latest'
  no_checksum
  link 'Soulver.app'
end  

In Soulver's case the download URL does always refer to the latest version. So in this case I used no_checksum, so that this Cask will not break in the future.

Now audit your cask:

$ brew cask audit soulver
audit for soulver: passed

Now you can install Soulver. And don't forget to open a pull request 😉

Before you do — check the latest contribution guidelines.

Conclusion

I am really happy that homebrew-cask exists now. It closed a gap in my configuration management. I can set up a new Mac in no time. I hope you enjoy it as much as I do.

9 Comments

  1. Hi Robert,

    Firstly, thank you for writing on homebrew-cask. I was looking around to find an easy way to setup a Mac from a fresh install, and your articles(including homesick) have been a great help.

    I was wondering though if you know how homebrew-cask manage the installers for the downloaded applications.

    For now, I just go to /Library/Cache/Homebrew and manually delete the files. Is there a way to thrash all the installers after installing the applications?

  2. Robert Curth

    August 28, 2013 at 4:28 pm

    Hi Zaki. Thanks for the praise.

    Homebrew-cask uses brew itself to manage the cache.

    $ brew cleanup -s

    Should do the job.

    If you want to automate this you can use:

    $ rm -rf $(brew --cache)

    You find further informations on the man page of homebrew:

    $ man brew

  3. Hi Robert,

    Your post convinces me to use homebrew cask, thanks for it.
    Do you know what to do when an app has an update?
    Do I have to "brew update" or simply update the app as usual?

    For example, in Google Chrome I click "Update Google Chrome" when there is an update. But I would know if it's the right way to update.

  4. Robert Curth

    January 3, 2014 at 4:33 pm

    There was some discussion about adding this to homebrew cask a while ago, but no work was done yet.

    https://github.com/phinze/home...

    You can update apps in via:

    $ brew cask install --force app-name

    The problem: many download urls are version specific, since not all applications have urls for the latest version.

    For these apps the download url has to be changed to the current one, whenever a new version comes out. That's why these Casks usually lag behind.

    Currently it's best to use the update mechanisms of the apps themselves. (Especially in case of security patches etc.)

  5. All right! Thank you, Robert.

  6. Update: The repository has moved to https://github.com/caskroom/ho.... You'll need to migrate, and instructions are available at that URL how to migrate. If you've not already tapped phinze/homebrew-cask, you can just do `brew tap caskroom/cask`.

  7. Zaki Juhari It's been awhile since this was first posted, but I just wanted to share a CLI script that I made specifically to uninstall Homebrew, as well as other helpful little things like finding Homebrew-related files on your system. It's been working fantastically, and has had good reception from the community so far. I encourage anyone who uses Homebrew to check it out!

    The gist can be found here.

    P.S. Geez. The link I posted has literally no discernable styling - in case anyone missed the link on word 'here', I present the URL: https://gist.github.com/SteveB...

  8. Robert Curth

    August 12, 2014 at 5:17 am

    Thanks for the link Stephen 🙂

  9. Mochamad Iqbal Dwi Cahyo

    March 2, 2016 at 5:57 am

    Thanks, nice articles! 🙂

Leave a Reply

Your email address will not be published.

*

© 2017 Rocu.de

Theme by Anders NorenUp ↑