Cache brew install on osx


This is a similar question to: How do I cache brew install node?

I need go installed for a cross-platform XCode project. This step works perfectly fine but it usually takes 3-4 minutes, just to update homebrew and then it rather quickly fetches the binary.

    - run:
        name: install Go
        command: brew install go

I would be fine with fetching and unpacking the version of go I need myself into the home directory, I just wasn’t what the best course of action is here. Could also I bake that install step into the vm image or should I use caching instead?

Are you on cloud? Because you won’t be able to modify the vm image. I think you’ll have the easiest time with downloading the binary and caching it. You can run a step that downloads it and unpacks it. Then cache it with the normal cache command and some key that will always persist.

      - restore_cache:
            - go-bin-v-whatever

      - run: (check if go binary exists - if not then download it)

      - save_cache:
          key: go-bin-v-whatever
            - "gobinaryfolder"

Then you can use the -go-bin-v-whatever key to restore the binary in jobs and use it.

Assuming that the version available at the time the image was created is fine (which I’ll assume is fine go but maybe not other environments which update more frequently) you can set HOMEBREW_NO_AUTO_UPDATE in your environment to avoid the slowish update phase.