Installing bazel 0.24.1 from Source Code

  1. Install the system dependencies. Ubuntu and CentOS are used as examples.
    • Ubuntu 18.04 x86_64:
      apt-get install build-essential openjdk-11-jdk python zip unzip
    • CentOS 8.3 aarch64 environment:
      yum install java-11-openjdk-devel.aarch64
      yum install java-11-openjdk.aarch64
      yum groupinstall 'Development Tools'
      yum install zip

    If java-11-openjdk fails to be installed, manually install it by referring to Installing java-11-openjdk1 Manually.

  2. Set environment variables.
    1. Open the .bashrc file.
      vim ~/.bashrc
    2. Add the java-11-openjdk installation path to the file. (The path in the following command is simply an example. Replace it with the actual installation path.)
      export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
      export PATH=$JAVA_HOME/bin:$PATH
    3. Run the :wq! command to save the file and exit.
    4. Run the following command for the environment variables to take effect:
      source ~/.bashrc
  3. Download the bazel compressed source package and upload it to any directory on the server.
  4. Go to the directory where the source package is stored and perform compilation and installation.
    1. Decompress the downloaded bazel source package.
      unzip bazel-0.24.1-dist.zip -d bazel-0.24.1-dist
    2. Go to the decompressed folder, and run the following configuration, compilation, and installation commands:
      cd bazel-0.24.1-dist/
      env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" ./compile.sh
      cp output/bazel /usr/local/bin
  5. Validate your installation.

    After the installation is complete, run the following command to check the version:

    bazel --version