Installing Bazel on Windows
1. Check your system
Recommended: 64 bit Windows 10, version 1703 (Creators Update) or newer, enable “Developer Mode”.
Also supported:
-
64 bit Windows 7 or newer
-
64 bit Windows Server 2008 R2 or newer
2. Install the prerequisites
-
You should use the default install path.
-
MSYS2 packages
Open the MSYS2 terminal, and run this command:
pacman -S zip unzip patch diffutils git
3. Download Bazel
Download the Bazel binary (bazel-<version>-windows-x86_64.exe
) from
GitHub.
Recommended: rename this binary to bazel.exe
and move it to a directory on the PATH
.
Alternatively you can:
- Install from Chocolatey (see below)
- Install from Scoop (see below)
- Build from source
4. Optional: install compilers
You can skip this step. Bazel can work without these programs, but you may need them.
We recommend installing:
-
Build Tools for Visual Studio 2019
Make sure you install the C++ build tools with the Windows 10 SDK.
You will need this to build C++ code on Windows.
Also supported:
-
Visual Studio 2015 (or newer) with Visual C++ and Windows 10 SDK
-
Visual C++ Build Tools 2015 (or newer) and Windows 10 SDK
-
-
Java SE Development Kit 10 (JDK) for Windows x64
You will need this to build Java code on Windows.
Also supported: Java 8, 9
-
You will need this to build Python code on Windows.
Also supported: Python 3 or newer for Windows x86-64
5. Done
You have successfully installed Bazel.
Troubleshooting: see the “Appendix” > “Troubleshooting” section below.
Tutorials: see the “Tutorials” section on the left navigation panel.
Appendix
Table of contents:
Troubleshooting
Problem: Bazel does not find Bash or bash.exe
Possible reasons:
-
you installed MSYS2 not under the default install path
-
you installed MSYS2 i686 instead of MSYS2 x86_64
-
you installed MSYS instead of MSYS2
Solution:
Ensure you installed MSYS2 x86_64.
If that doesn’t help:
-
Go to Start Menu > Settings.
-
Find the setting “Edit environment variables for your account”
-
Look at the list on the top (“User variables for <username>”), and click the “New…” button below it.
-
For “Variable name”, enter
BAZEL_SH
-
Click “Browse File…”
-
Navigate to the MSYS2 directory, then to
usr\bin
below it.For example, this might be
C:\msys64\usr\bin
on your system. -
Select the
bash.exe
orbash
file and click OK -
The “Variable value” field now has the path to
bash.exe
. Click OK to close the window. -
Done.
If you open a new cmd.exe or PowerShell terminal and run Bazel now, it will find Bash.
Problem: Bazel does not find Visual Studio or Visual C++
Possible reasons:
-
you installed multiple versions of Visual Studio
-
you installed and removed various versions of Visual Studio
-
you installed various versions of the Windows SDK
-
you installed Visual Studio not under the default install path
Solution:
-
Go to Start Menu > Settings.
-
Find the setting “Edit environment variables for your account”
-
Look at the list on the top (“User variables for <username>”), and click the “New…” button below it.
-
For “Variable name”, enter
BAZEL_VC
-
Click “Browse Directory…”
-
Navigate to the
VC
directory of Visual Studio.For example, this might be
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC
on your system. -
Select the
VC
folder and click OK -
The “Variable value” field now has the path to
VC
. Click OK to close the window. -
Done.
If you open a new cmd.exe or PowerShell terminal and run Bazel now, it will find Visual C++.
Other ways to install Bazel
Install using Chocolatey
-
Install the Chocolatey package manager
-
Install the Bazel package:
choco install bazel
This command will install the latest available version of Bazel and its dependencies, such as the MSYS2 shell. This will not install Visual C++ though.
See Chocolatey installation and package maintenance guide for more information about the Chocolatey package.
Install using Scoop
-
Install the Scoop package manager using the following PowerShell command:
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
-
Install the Bazel package:
scoop install bazel
See Scoop installation and package maintenance guide for more information about the Scoop package.