bazel installation via the bazelisk method

2024/08/24

bazel installation via the bazelisk method

Here is how I install bazel. I use this installation method on all of my machines. I do not think it is practical to go about this any other way. It is implied in all of my writings about bazel.

Why?

Sadly, bazel versions are wildly incompatible between major version releases. This means that as you encounter projects using newer and newer bazel versions, you may encounter random compatibility issues.

To work around that, bazelisk will recognize the version of bazel that your build needs, and will download and run the correct version for you automatically.

How?

I install bazelisk, and let it download and use the appropriate bazel version for each project.

Recipe

  1. Download bazelisk for your platform, and place it somewhere on your machine’s drive.
  2. Create a symlink named bazel somewhere in your $PATH, pointing to the just downloaded bazelisk library.
  3. Add the .bazelversion file in each project, to fix the bazel version for that project.
  4. If you store your project on Github, ensure you are using the correct bazel version in your workflows.