Project: /_project.yaml Book: /_book.yaml
{% include “_buttons.html” %}
This page describes how to install Bazel from source and provides troubleshooting tips for common issues.
To build Bazel from source, you can do one of the following:
Build it using an existing Bazel binary
Build it without an existing Bazel binary which is known as bootstrapping.
Get the latest Bazel release from the GitHub release page{: .external} or with Bazelisk{: .external}.
Download Bazel's sources from GitHub{: .external} and extract somewhere. Alternatively you can git clone the source tree from https://github.com/bazelbuild/bazel
Install the same prerequisites as for bootstrapping (see for Unix-like systems or for Windows)
Build a development build of Bazel using Bazel: bazel build //src:bazel-dev
(or bazel build //src:bazel-dev.exe
on Windows)
The resulting binary is at bazel-bin/src/bazel-dev
(or bazel-bin\src\bazel-dev.exe
on Windows). You can copy it wherever you like and use immediately without further installation.
Detailed instructions follow below.
Goal: Install or download a release version of Bazel. Make sure you can run it by typing bazel
in a terminal.
Reason: To build Bazel from a GitHub source tree, you need a pre-existing Bazel binary. You can install one from a package manager or download one from GitHub. See Installing Bazel. (Or you can build from scratch (bootstrap).)
Troubleshooting:
If you cannot run Bazel by typing bazel
in a terminal:
Maybe your Bazel binary's directory is not on the PATH.
This is not a big problem. Instead of typing bazel
, you will need to type the full path.
Maybe the Bazel binary itself is not called bazel
(on Unixes) or bazel.exe
(on Windows).
This is not a big problem. You can either rename the binary, or type the binary's name instead of bazel
.
Maybe the binary is not executable (on Unixes).
You must make the binary executable by running chmod +x /path/to/bazel
.
If you are familiar with Git, then just git clone https://github.com/bazelbuild/bazel
Otherwise:
Download the latest sources as a zip file{: .external}.
Extract the contents somewhere.
For example create a bazel-src
directory under your home directory and extract there.
Install the same prerequisites as for bootstrapping (see below) -- JDK, C++ compiler, MSYS2 (if you are building on Windows), etc.
For instructions for Windows, see Build Bazel on Windows.
Goal: Run Bazel to build a custom Bazel binary (bazel-bin/src/bazel-dev
).
Instructions:
Start a Bash terminal
cd
into the directory where you extracted (or cloned) Bazel's sources.
For example if you extracted the sources under your home directory, run:
cd ~/bazel-src
Build Bazel from source:
bazel build //src:bazel-dev
Alternatively you can run bazel build //src:bazel --compilation_mode=opt
to yield a smaller binary but it's slower to build.
The output will be at bazel-bin/src/bazel-dev
(or bazel-bin/src/bazel
).
For instructions for Unix-like systems, see Ubuntu Linux, macOS, and other Unix-like systems.
Goal: Run Bazel to build a custom Bazel binary (bazel-bin\src\bazel-dev.exe
).
Instructions:
Start Command Prompt (Start Menu > Run > “cmd.exe”)
cd
into the directory where you extracted (or cloned) Bazel's sources.
For example if you extracted the sources under your home directory, run:
cd %USERPROFILE%\bazel-src
Build Bazel from source:
bazel build //src:bazel-dev.exe
Alternatively you can run bazel build //src:bazel.exe --compilation_mode=opt
to yield a smaller binary but it's slower to build.
The output will be at bazel-bin\src\bazel-dev.exe
(or bazel-bin\src\bazel.exe
).
Actually, there's nothing to install.
The output of the previous step is a self-contained Bazel binary. You can copy it to any directory and use immediately. (It's useful if that directory is on your PATH so that you can run “bazel” everywhere.)
You can also build Bazel from scratch, without using an existing Bazel binary.
(This step is the same for all platforms.)
Download bazel-<version>-dist.zip
from GitHub{: .external}, for example bazel-0.28.1-dist.zip
.
Attention:
Unpack the distribution archive somewhere on disk.
You should verify the signature made by Bazel's release key 3D5919B448457EE0.
For instructions for Windows, see Bootstrap Bazel on Windows.
Bash
zip, unzip
C++ build toolchain
JDK. Version 21 is required.
Python. Versions 2 and 3 are supported, installing one of them is enough.
For example on Ubuntu Linux you can install these requirements using the following command:
sudo apt-get install build-essential openjdk-21-jdk python zip unzip
Open a shell or Terminal window.
cd
to the directory where you unpacked the distribution archive.
Run the compilation script: env EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" bash ./compile.sh
.
The compiled output is placed into output/bazel
. This is a self-contained Bazel binary, without an embedded JDK. You can copy it anywhere or use it in-place. For convenience, copy this binary to a directory that's on your PATH
(such as /usr/local/bin
on Linux).
To build the bazel
binary in a reproducible way, also set SOURCE_DATE_EPOCH
in the “Run the compilation script” step.
For instructions for Unix-like systems, see Bootstrap Bazel on Ubuntu Linux, macOS, and other Unix-like systems.
The MSYS2 packages for zip and unzip. Run the following command in the MSYS2 shell:
pacman -S zip unzip patch
The Visual C++ compiler. Install the Visual C++ compiler either as part of Visual Studio 2015 or newer, or by installing the latest Build Tools for Visual Studio 2017.
JDK. Version 21 is required.
Python. Versions 2 and 3 are supported, installing one of them is enough. You need the Windows-native version (downloadable from https://www.python.org). Versions installed via pacman in MSYS2 will not work.
Open the MSYS2 shell.
Set the following environment variables:
Either BAZEL_VS
or BAZEL_VC
(they are not the same): Set to the path to the Visual Studio directory (BAZEL_VS) or to the Visual C++ directory (BAZEL_VC). Setting one of them is enough.
BAZEL_SH
: Path of the MSYS2 bash.exe
. See the command in the examples below.
Do not set this to C:\Windows\System32\bash.exe
. (You have that file if you installed Windows Subsystem for Linux.) Bazel does not support this version of bash.exe
.
PATH
: Add the Python directory.
JAVA_HOME
: Set to the JDK directory.
Example (using BAZEL_VS):
export BAZEL_VS="C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools" export BAZEL_SH="$(cygpath -m $(realpath $(which bash)))" export PATH="/c/python27:$PATH" export JAVA_HOME="C:/Program Files/Java/jdk-21"
or (using BAZEL_VC):
export BAZEL_VC="C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC" export BAZEL_SH="$(cygpath -m $(realpath $(which bash)))" export PATH="/c/python27:$PATH" export JAVA_HOME="C:/Program Files/Java/jdk-21"
cd
to the directory where you unpacked the distribution archive.
Run the compilation script: env EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" ./compile.sh
The compiled output is placed into output/bazel.exe
. This is a self-contained Bazel binary, without an embedded JDK. You can copy it anywhere or use it in-place. For convenience, copy this binary to a directory that's on your PATH
.
To build the bazel.exe
binary in a reproducible way, also set SOURCE_DATE_EPOCH
in the “Run the compilation script” step.
You don't need to run Bazel from the MSYS2 shell. You can run Bazel from the Command Prompt (cmd.exe
) or PowerShell.