How do you install bazel using bazelisk

Viewed 9206

Or better yet, how do you install bazel at all. I have been using cd to get into a folder on my desktop, then I used git clone https://github.com/bazelbuild/bazelisk and then? What am I supposed to do now, honestly I didn't find any real instruction for this, I have many folder in there now, am I supposed to run a special file like bazelisk.py now? Or like build it? Was I supposed to clone the github repository in a special location? As mentioned I just choose a folder on my desktop, but I added the path to my Path enviromental variable, I added C:\Users\user\Desktop\folder\bazel and C:\Users\user\Desktop\folder\bazel\bazelisk because I wasn't sure how far I should go. So if anybody could show me how to install bazel at all I would be thankful, I just need it for a python project, I am using python 3.6.2 and I am on windows 10. I don't know what to do now because the installation steps I've read only go as far as saying to git clone the repository, but when I enter cmd and type bazel or bazel help cmd can not find the command.

2 Answers

From Official Bazel Documentation

https://github.com/bazelbuild/bazelisk/blob/master/README.md ->

Bazelisk is a wrapper for Bazel written in Go. It automatically picks a good version of Bazel given your current working directory, downloads it from the official server (if required) and then transparently passes through all command-line arguments to the real Bazel binary. You can call it just like you would call Bazel.

Steps to Installing Bazelisk in Linux/Mac/Windows

Below steps show installation of bazelisk v1.8.1, but you can install any desired version from https://github.com/bazelbuild/bazelisk/releases using same steps

Steps for Bazelisk Linux Install

> wget https://github.com/bazelbuild/bazelisk/releases/download/v1.8.1/bazelisk-linux-amd64
> chmod +x bazelisk-linux-amd64
> sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel
     
# make sure you get the binary available in $PATH
> which bazel
bazel is /usr/local/bin/bazel

Steps for Bazelisk Mac Install

wget https://github.com/bazelbuild/bazelisk/releases/download/v1.8.1/bazelisk-darwin-amd64
chmod +x bazelisk-darwin-amd64
sudo mv bazelisk-darwin-amd64 /usr/local/bin/bazel

Steps for Bazelisk Windows Install

Download and install Bazelisk windows binary from https://github.com/bazelbuild/bazelisk/releases

How to use Bazelisk and set desired Bazel version

  • If the environment variable USE_BAZEL_VERSION is set, it will use the version specified in the value.

  • Otherwise, if a .bazeliskrc file exists in the workspace root and contains the USE_BAZEL_VERSION variable, this version will be used.

  • Otherwise, if a .bazelversion file exists in the current directory or recursively any parent directory, it will read the file and use the version specified in it.

  • Otherwise it will use the official latest Bazel release.

Since you are using Windows I will describe the Windows way of doing it (it is also similar on other platforms)

Download a prebuild version of bazelisk.exe. You can find prebuilt versions here. For instance, v1.7.4. Then rename bazelisk-windows-amd64.exe to bazelisk.exe and add it to your PATH environment variable. When you open now a PowerShell and type bazelisk info you should see some output.

bazelisk is only a wrapper around bazel which means you have still to setup everything to make Bazel working on your system. bazelisk just redirects all commands to Bazel. bazelisk just cares about which version of Bazel is used (e.g. you can define in a .bazelversion file wich version of Bazel should be used). I suggest you to follow the instructions listed here that describe what needs to be done to get Bazel working on Windows (for instance installing MSYS2 makes sense).

Related