This post will guide you how to install Bazel on Ubuntu 16.04/18.04 Linux server. How do I install Bazel tool using the binary installer on Ubuntu Linux server. How to install Bazel software with the custom APT repository on Ubuntu. How to install Bazel by compiling Bazel from source package on Ubuntu.
What is Bazel?
Bazel is a free software tool that allows for the automation of building and testing of software. The company Google uses the build tool Blaze internally and released and open-sourced part of the Blaze tool as Bazel, named as an anagram of Blaze.
Bazel is an open-source build and test tool similar to Make, Maven, and Gradle. It uses a human-readable, high-level build language. Bazel supports projects in multiple languages and builds outputs for multiple platforms. Bazel supports large codebases across multiple repositories, and large numbers of users.
Install Bazel via Binary Installer
The latest version of Bazel is 0.22.0. And you can get the binary installer of Bazel from the Bazel’s GitHub releases page. . And you can refer to the following steps to install Bazel on your Ubuntu Linux:
#1 you need to install all of required packages for Bazel with the following command:
$ sudo apt install pkg-config zip g++ zliblg-dev unzip python
Outputs:
devops@devops-osetc:~$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python Reading package lists... Done Building dependency tree Reading state information... Done pkg-config is already the newest version (0.29.1-0ubuntu2). python is already the newest version (2.7.15~rc1-1). unzip is already the newest version (6.0-21ubuntu1). zip is already the newest version (3.0-11build1). zlib1g-dev is already the newest version (1:1.2.11.dfsg-0ubuntu2). zlib1g-dev set to manually installed. g++ is already the newest version (4:7.3.0-3ubuntu2.1). The following packages were automatically installed and are no longer required: libllvm6.0 x11proto-dri2-dev x11proto-gl-dev Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Those packages should be installed by default on Ubuntu 16.04 or 18.04 Linux.
#2 You can download the Bazel binary installer script to your local disk with the wget tool from the Bazel releases page on GitHub, type:
$ wget https://github.com/bazelbuild/bazel/releases/download/0.22.0/bazel-0.22.0-installer-linux-x86_64.sh
Outputs:
devops@devops-osetc:~$ wget https://github.com/bazelbuild/bazel/releases/download/0.22.0/bazel-0.22.0-installer-linux-x86_64.sh --2019-01-05 11:25:16-- https://github.com/bazelbuild/bazel/releases/download/0.22.0/bazel-0.22.0-installer-linux-x86_64.sh Resolving www-proxy.us.osetc.com (www-proxy.us.osetc.com)... 148.87.19.20 Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|148.87.19.20|:80... connected. Proxy request sent, awaiting response... 302 Found Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/20773773/63598600-2309-11e9-848f-e7b3ff38b1d2?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190219%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190219T055453Z&X-Amz-Expires=300&X-Amz-Signature=249fa877cfba5d5091a67391abd0cfa660effaaa9ec025639ea1e5f25e10680c&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dbazel-0.22.0-installer-linux-x86_64.sh&response-content-type=application%2Foctet-stream [following] --2019-01-05 11:25:17-- https://github-production-release-asset-2e65be.s3.amazonaws.com/20773773/63598600-2309-11e9-848f-e7b3ff38b1d2?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190219%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190219T055453Z&X-Amz-Expires=300&X-Amz-Signature=249fa877cfba5d5091a67391abd0cfa660effaaa9ec025639ea1e5f25e10680c&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dbazel-0.22.0-installer-linux-x86_64.sh&response-content-type=application%2Foctet-stream Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|148.87.19.20|:80... connected. Proxy request sent, awaiting response... 200 OK Length: 168649438 (161M) [application/octet-stream] Saving to: ‘bazel-0.22.0-installer-linux-x86_64.sh’ bazel-0.22.0-installer-linux-x86_64.sh 100%[==========================================================================>] 160.84M 344KB/s in 8m 3s 2019-01-05 11:33:22 (341 KB/s) - ‘bazel-0.22.0-installer-linux-x86_64.sh’ saved [168649438/168649438] devops@devops-osetc:~$ ls bazel-0.22.0-installer-linux-x86_64.sh bazel-0.22.0-installer-linux-x86_64.sh
#3 run the downloaded binary installer of Bazel on your Ubuntu terminal, type:
$ chmod u+x bazel-0.22.0-installer-linux-x86_64.sh $ sudo ./bazel-0.22.0-installer-linux-x86_64.sh --user
Outputs:
$ sudo ./bazel-0.22.0-installer-linux-x86_64.sh --user Uncompressing....... Bazel is now installed! Make sure you have "/home/devops/bin" in your path. You can also activate bash completion by adding the following line to your ~/.bashrc: source /home/devops/.bazel/bin/bazel-complete.bash See http://bazel.build/docs/getting-started.html to start a new project!
Note: the –user argument indicates that it will install Bazel to the $HOME/bin directory on your system and sets the .bazelrc path to $HOME/.bazelrc. You can use the –help option to check additional installation options for this binary installer. Such as:
$ sudo ./bazel-0.22.0-installer-linux-x86_64.sh --help
Outputs:
devops@devops-osetc:~$ ./bazel-0.22.0-installer-linux-x86_64.sh --help Bazel installer --------------- Bazel is bundled with software licensed under the GPLv2 with Classpath exception. You can find the sources next to the installer on our release page: https://github.com/bazelbuild/bazel/releases # Release 0.22.0 (2019-01-28) Baseline: deb028e3fb30b4e2953df16f35ab1f55a08ea8fa Cherry picks: + a3a5975dca3ad04c19dc7d063fcf490a8cd612fd: Fix a race condition in remote cache + b8d0e1b05c225a4b943ce498194d069d18093d9a: ...... New features: - Add inputs filtering for aquery - https://docs.bazel.build now supports versioned documentation. Use the selector at the top of the navigation bar to switch between documentation for different Bazel releases. - build_tar.py in tools/build_defs/pkg now supports a json manifest that can be used to add paths that have symbols that can't be specified via the command line Important changes: - Added `--incompatible_dont_emit_static_libgcc` (https://github.com/bazelbuild/bazel/issues/6825) Added `--incompatible_linkopts_in_user_link_flags` (https://github.com/bazelbuild/bazel/issues/6826) - mobile-install now works with aapt2. Try it out with `bazel mobile-install --android_aapt=aapt2 //my:target` ...... ## Build informations - [Commit](https://github.com/bazelbuild/bazel/commit/2a11637) Usage: ./bazel-0.22.0-installer-linux-x86_64.sh [options] Options are: --prefix=/some/path set the prefix path (default=/usr/local). --bin= set the binary folder path (default=%prefix%/bin). --base= set the base install path (default=%prefix%/lib/bazel). --user configure for user install, expands to: --bin=$HOME/bin --base=$HOME/.bazel --skip-uncompress skip uncompressing the base image until the first bazel invocation
Install Bazel Using Custom APT Repository
You can also use the APT repository to install Bazel on your Ubuntu server. you need to install the JDK 8 firstly, and install the Bazel package with apt or apt-get install command directly. Here are the steps:
#1 Install the JDK 8 Package firstly with the following command:
$ sudo apt install openjdk-8-jdk
If you are using Ubuntu 14.04, you need to add a new apt respsitory, then install JDK 8, type:
$ sudo add-apt-repository ppa:webupd8team/java $ sudo apt update && sudo apt install oracle-java8-installer
#2 you need to add the Bazel distribution URI to a new package source list file, type:
$ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list $ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
#3 install Bazel package on your Ubuntu Linux,type:
$ apt update $ apt install bazel
Conclusion
You should know that how to install Bazel on your Ubuntu 14.04 or 16.04 or 18.04 Linux from this guide. And if you want to learn more about the Bazel, you can go the below official web site to checking the getting started guide directly.