There are a few ways to setup Bazel. After setup, you should expect the bazel
command to work, and ideally command-line completion should work in your shell.
At some companies, your Dev Infra team may have already setup a specific way Bazel should be used for the project you're coding on. Take care not to change the setup of your computer in a way that interferes with doing your work!
Simplest
Bazel publishes release binaries, which are assets you can download from GitHub, see Embed GitHub. You typically rename the downloaded file to bazel
and put it on your PATH
. On macOS, you can run xattr -c $(which bazel)
to remove the “Unknown Developer” warning.
However, this approach is not recommended as it risks version drift against coworkers and CI. When the Bazel version in your repo changes, you’ll be running the wrong one and likely get confusing errors.
Bazelisk
Bazelisk (https://bazel.build/install/bazelisk) is the installation recommended by the Bazel team at Google. It is a version-aware wrapper that downloads the correct Bazel version using the .bazelversion
file you’ll see later. Typically, developers rename it to bazel
on the PATH
, so you don't need to think about the distinction.
- macOS:
brew install bazelisk
- npm:
npm install -g @bazel/bazelisk
Aspect CLI
This course uses the Aspect CLI as a wrapper for bazel
. It has features to make Bazel easier to learn, such as improved output from bazel help
and added commands like bazel lint
. It's meant to improve your experience while remaining fully backwards compatible. You could go back to "vanilla Bazel" at any time.
- You can install it for yourself, replacing both of the previous alternatives.
- macOS:
brew install aspect-build/aspect/aspect
- It can be used with Bazelisk, which stores settings in a
.
bazeliskrc
file checked into source control to install it for your team. This way, any engineer who runs Bazelisk (generally asbazel
on their$PATH
) gets the Aspect-provided commands. You use this in the lesson.
Don’t worry if your team isn’t planning to use Aspect CLI as part of your work. This training calls out any features which are only in the Aspect CLI and suggests alternatives you can use with vanilla bazel
. For example:
Aspect CLI only
The bazel docs
command opens documentation in your browser. For example, run bazel docs glossary
to learn all of Bazel's terminology. Run bazel docs aspect_rules_js
to see documentation for @aspect_rules_js
loads.
If using “vanilla Bazel”, search for docs in your favorite search engine.
Try it
Let’s make sure Bazel is working on your computer. Run bazel help
to get familiar with it.
You may also run bazel version
to verify the installation.
If you see
WARNING: Invoking Bazel in batch mode since it is not invoked from within a workspace
don't worry. You'll fix that in the next section.
If you prefer not to run commands on your computer, follow along with the instructor to see all the exercises presented.