Skip to content

Bazel Setup

Bazel official site recommended bazelisk. For linux users, they recommend download the release, for example, to local and treat it as bazel.

In MacOS, use Homebrew package management tool can easily install Bazel/Bazelisk and relevant tools. (you can search for other packages in Homebrew's online package browser)

# install bazel
brew install bazelisk

# install bazel tools
brew install buildifier
brew install buildozer

For each package, Homebrew will create a symlink under /opt/homebrew. For binaries, Homebrew will create a symlink under /opt/homebrew/bin, which could already be part of your $PATH. For example, you will see following after you install bazelisk

$ which bazel
/opt/homebrew/bin/bazel

Searching online, I found the following scripts

# use wget to download the release
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-linux-amd64

# make the downloaded file executable. My desktop with Linux OS is x86_64 architecture, so use amd64; Mac may need arm64
chmod +x bazelisk-linux-amd64

# move the executable to dir
mkdir /usr/local/bin/bazel
mv bazelisk-linux-amd64 /usr/local/bin/bazel/

# we can rename the executable to bazel directly, but I chose to use a symlink.
ln -s bazelisk-linux-amd bazel

Then I need to add this bazel into $PATH. Because I envision I would have quite a few configurations, I created a profile.d/ directory here and created a .bashrc file for this monorepo use. I will see how to curate these configurations in the future

Similarly, we can download and install buildifier and buildozer for rewrite and reformatting the BUILD files. These two tools are part of the bazel build tools