Skip to content

Instantly share code, notes, and snippets.

@evie404
Last active December 13, 2018 23:24
Show Gist options
  • Save evie404/18a31bd2a1790dfcf4bb3780898678c8 to your computer and use it in GitHub Desktop.
Save evie404/18a31bd2a1790dfcf4bb3780898678c8 to your computer and use it in GitHub Desktop.

Managing multiple-versions of Bazel with Homebrew

If you work with multiple repositories that require different versions of Bazel, this guide might help.

Installing a version of Bazel

Homebrew has a mechanism for installing an older version of a particular package. The details are in this Stackoverflow answer for those interested.

The general idea is to find the particular SHA of homebrew-core and install the bazel formula from a particular commit. You can find the history of all Bazel recipe changes in: https://github.com/Homebrew/homebrew-core/commits/master/Formula/bazel.rb.

The command is:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<commit sha>/Formula/bazel.rb

And you'll find the commands for the specific versions of Bazel in the latter part of this guide.

Listing the versions of Bazels installed

brew info bazel

If you have multiple versions installed, the version that is currently linked will appear with a *.

Example:

$ brew info bazel
bazel: stable 0.15.2 (bottled)
Google's own build tool
https://bazel.build/
/usr/local/Cellar/bazel/0.8.1 (12 files, 91.3MB)
  Poured from bottle on 2018-07-30 at 10:56:42
/usr/local/Cellar/bazel/0.13.0 (12 files, 107.7MB)
  Poured from bottle on 2018-05-21 at 10:44:58
/usr/local/Cellar/bazel/0.13.1 (12 files, 107.7MB)
  Poured from bottle on 2018-05-31 at 13:28:53
/usr/local/Cellar/bazel/0.14.0 (12 files, 108.9MB)
  Poured from bottle on 2018-06-01 at 10:35:40
/usr/local/Cellar/bazel/0.14.1 (12 files, 108.9MB)
  Poured from bottle on 2018-06-08 at 10:27:10
/usr/local/Cellar/bazel/0.15.0 (12 files, 109MB)
  Poured from bottle on 2018-06-27 at 02:05:05
/usr/local/Cellar/bazel/0.15.1 (12 files, 109MB)
  Poured from bottle on 2018-07-16 at 11:20:18
/usr/local/Cellar/bazel/0.15.2 (12 files, 109MB) *
  Poured from bottle on 2018-07-20 at 09:45:02
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/bazel.rb
==> Requirements
Required: java = 1.8 ✔, macOS >= 10.10 ✔
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

I'm using 0.15.2 in this example. Which is indicated by:

/usr/local/Cellar/bazel/0.15.2 (12 files, 109MB) *
  Poured from bottle on 2018-07-20 at 09:45:02

Switching to a different version of Bazel

brew switch bazel <bazel version>

Note that this switch is global. If you work with a repo that requires 0.15.2, then switch to a repo that uses 0.8.1 without running the brew switch command, if you run bazel against the repo, it will attempt to build with 0.15.2, which was the last used version.

Example:

$ brew switch bazel 0.15.2
4 links created for /usr/local/Cellar/bazel/0.15.2

$ bazel version
Build label: 0.15.2-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Jul 17 13:06:19 2018 (1531832779)
Build timestamp: 1531832779
Build timestamp as int: 1531832779

$ brew switch bazel 0.13.1 
4 links created for /usr/local/Cellar/bazel/0.13.1

$ bazel version
Build label: 0.13.1-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed May 23 16:57:59 2018 (1527094679)
Build timestamp: 1527094679
Build timestamp as int: 1527094679

Installing specific version of Bazel

To install 0.20.0:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/da863ab7d8122b8ad406eb5e8bb2253953e6bcc9/Formula/bazel.rb

To install 0.19.2:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/14c9ff0f576d13737e0bcfbb608a504b8637c8fb/Formula/bazel.rb

To install 0.18.1:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/4a183c0ca570a8d0d26c240d40cf48dbc1a834f9/Formula/bazel.rb

To install 0.17.2:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/b729cc3bcf6feeb1f49a5f24a509db39926bf1c9/Formula/bazel.rb

To install 0.15.2:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/18f6319a63e1c882c695d2ef646cd8772127b1c4/Formula/bazel.rb

To install 0.14.1:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f691b5ed6844c5df632164b928cfefac02952130/Formula/bazel.rb

To install 0.13.1:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/58d007d315246fb7dfb59e4638c0aa6431e22bfc/Formula/bazel.rb

To install 0.12.0:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/be493be80014bbb93eef7b961538fe0fd9eb9fd9/Formula/bazel.rb

To install 0.11.1:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/885a2053e9e58655d6220e009f4de6211c235558/Formula/bazel.rb

To install 0.10.1:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/44ac5138dcd105ec2872ddbe39801764dbb380e8/Formula/bazel.rb

To install 0.9.0:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/bd8bba7e722fa93cf140b9e901bffabc86c98565/Formula/bazel.rb

To install 0.8.1:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/6046fe6043fc9f660d05a8879753d666a878d583/Formula/bazel.rb

To install 0.7.0:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/51a14faf1fd287328aed93a671e7657bb598e32e/Formula/bazel.rb

Homebrew only has these versions of Bazels available at the time of writing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment