Caching go on Mac OS build environment?

Has anyone installed go on Mac OS build environment and then saved it to cache for future builds and restoring from cache at the start thereafter?

I attempted to do so along with caching for Android tooling being installed on Mac OS environment (Android SDK, NDK, platform tools).

So far the Android stuff seems to cache ok, but not go, that didn’t seem to properly persist to cache even though the save cache step ran and the go install was successful. On restore cache, the saved paths weren’t found for some reason.

The job config is like:

  <<: *defaults
  xcode: 11.3.0
  - restore_cache:
        - go-deps-v1
  - run:
      name: cache check for go stuff & install/setup if not cached
      command: |
        brew --version # just to check that brews installed, for debugging reference
        [ ! -d /usr/local/opt/go@1.13 ] && brew update && brew install go@1.13 && echo "done installing go"
        echo 'export GOPATH="$HOME/go"' >> $BASH_ENV
        echo 'export PATH="/usr/local/opt/go@1.13/bin:$GOPATH/bin:$PATH"' >> $BASH_ENV
        source $BASH_ENV
        go version
  - save_cache:
      key: go-deps-v1
        - /usr/local/opt/go@1.13
        - /usr/local/opt/go@1.13/bin
        - ~/go
        - ~/go/bin

Could you try using the absolute path (i.e. /Users/distiller/go/bin). I can’t seem to find it in the docs, but I can remember that there are some parts of the config that do not know how to handle relative paths.

Thanks, I’ll give that a try next time.

Hey, just wanted to throw a bone.
For me it’s working using the home path, but for full caching, i had to do both:
- ~/go/pkg
- ~/Library/Caches/go-build

Also, if you want to skip caching the go installation itself, but still not use brew (cause it’s taking a lot of time in circle) you can do the following:
# Install go
sudo mkdir -p /usr/local/go
sudo chown -R $(whoami): /usr/local/go
curl -sSL “” | sudo tar -xz -C /usr/local/
echo “export PATH=$PATH:/usr/local/go/bin” >> BASH_ENV sudo chown -R (whoami): /usr/local/go

It takes like 10 seconds to install

1 Like