blob: 7182ca440b007b6e7fcc33162ec36029312bfe89 [file] [log] [blame] [view]
Googler7cd006a2017-03-27 14:47:34 +00001---
Googler1fbef392017-03-22 09:05:09 +00002layout: documentation
Googler7cd006a2017-03-27 14:47:34 +00003title: Installing Bazel on Ubuntu
4---
Googler1fbef392017-03-22 09:05:09 +00005
Laszlo Csomor7b6d2fa2018-10-25 07:04:33 -07006<h1 id="ubuntu">Installing Bazel on Ubuntu</h1>
Googler1fbef392017-03-22 09:05:09 +00007
8Supported Ubuntu Linux platforms:
9
Jingwen Chen43f792d2018-11-06 07:40:09 -080010* 18.04 (LTS)
Googler1fbef392017-03-22 09:05:09 +000011* 16.04 (LTS)
Googlerc82a1612017-03-28 12:56:57 +000012* 14.04 (LTS)
Googler1fbef392017-03-22 09:05:09 +000013
14Install Bazel on Ubuntu using one of the following methods:
15
Serge70e84f82018-04-18 10:04:22 -070016* [Use the binary installer (recommended)](#install-with-installer-ubuntu)
17* [Use our custom APT repository](#install-on-ubuntu)
Or Shachar73fe48b2017-05-26 14:03:57 +020018* [Compile Bazel from source](install-compile-source.md)
Googler1fbef392017-03-22 09:05:09 +000019
20Bazel comes with two completion scripts. After installing Bazel, you can:
21
Laszlo Csomor7b6d2fa2018-10-25 07:04:33 -070022* Access the [bash completion script](completion.md#bash)
23* Install the [zsh completion script](completion.md#zsh)
Googler1fbef392017-03-22 09:05:09 +000024
Laszlo Csomor7b6d2fa2018-10-25 07:04:33 -070025<h2 id="install-with-installer-ubuntu">Installing using binary installer</h2>
Serge70e84f82018-04-18 10:04:22 -070026
27The binary installers are on Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases).
28
Michael Hacknerdbd62202019-04-17 08:50:42 -070029The installer contains the Bazel binary. Some additional libraries must also be
30installed for Bazel to work.
Serge70e84f82018-04-18 10:04:22 -070031
spomorskiff634f72018-04-18 10:34:42 -070032### Step 1: Install required packages
33
George Kalpakasfa26e6e2018-05-02 05:21:19 -070034First, install the prerequisites: `pkg-config`, `zip`, `g++`, `zlib1g-dev`, `unzip`, and `python`.
Serge70e84f82018-04-18 10:04:22 -070035
36```bash
37sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python
38```
39
spomorskiff634f72018-04-18 10:34:42 -070040### Step 2: Download Bazel
Serge70e84f82018-04-18 10:04:22 -070041
spomorskiff634f72018-04-18 10:34:42 -070042Next, download the Bazel binary installer named `bazel-<version>-installer-linux-x86_64.sh`
43from the [Bazel releases page on GitHub](https://github.com/bazelbuild/bazel/releases).
Serge70e84f82018-04-18 10:04:22 -070044
spomorskiff634f72018-04-18 10:34:42 -070045### Step 3: Run the installer
Serge70e84f82018-04-18 10:04:22 -070046
spomorskiff634f72018-04-18 10:34:42 -070047Run the Bazel installer as follows:
Serge70e84f82018-04-18 10:04:22 -070048
49```bash
50chmod +x bazel-<version>-installer-linux-x86_64.sh
51./bazel-<version>-installer-linux-x86_64.sh --user
52```
53
54The `--user` flag installs Bazel to the `$HOME/bin` directory on your system and
55sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` command to see
56additional installation options.
57
spomorskiff634f72018-04-18 10:34:42 -070058### Step 4: Set up your environment
Serge70e84f82018-04-18 10:04:22 -070059
60If you ran the Bazel installer with the `--user` flag as above, the Bazel
61executable is installed in your `$HOME/bin` directory. It's a good idea to add
62this directory to your default paths, as follows:
63
64```bash
65export PATH="$PATH:$HOME/bin"
66```
67
68You can also add this command to your `~/.bashrc` file.
69
Laszlo Csomor7b6d2fa2018-10-25 07:04:33 -070070<h2 id="install-on-ubuntu"> Using Bazel custom APT repository</h2>
Googler1fbef392017-03-22 09:05:09 +000071
spomorskiff634f72018-04-18 10:34:42 -070072### Step 1: Install the JDK
Googler1fbef392017-03-22 09:05:09 +000073
spomorskiff634f72018-04-18 10:34:42 -070074Install JDK 8:
Thomas Broyerd5930ea2017-07-10 15:29:17 +020075
76```bash
77sudo apt-get install openjdk-8-jdk
Googler1fbef392017-03-22 09:05:09 +000078```
Thomas Broyerd5930ea2017-07-10 15:29:17 +020079
spomorskiff634f72018-04-18 10:34:42 -070080On Ubuntu 14.04 LTS you must use a PPA:
Thomas Broyerd5930ea2017-07-10 15:29:17 +020081
82```bash
83sudo add-apt-repository ppa:webupd8team/java
84sudo apt-get update && sudo apt-get install oracle-java8-installer
85```
86
spomorskiff634f72018-04-18 10:34:42 -070087### Step 2: Add Bazel distribution URI as a package source
88
89**Note:** This is a one-time setup step.
Thomas Broyerd5930ea2017-07-10 15:29:17 +020090
91```bash
laszlocsomor79251002017-04-03 13:09:47 +000092echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
93curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
Googler1fbef392017-03-22 09:05:09 +000094```
95
spomorskiff634f72018-04-18 10:34:42 -070096If you want to install the testing version of Bazel, replace `stable` with `testing`.
Googler1fbef392017-03-22 09:05:09 +000097
spomorskiff634f72018-04-18 10:34:42 -070098### Step 3: Install and update Bazel
Googler1fbef392017-03-22 09:05:09 +000099
laszlocsomor79251002017-04-03 13:09:47 +0000100```bash
101sudo apt-get update && sudo apt-get install bazel
102```
Googler1fbef392017-03-22 09:05:09 +0000103
spomorskiff634f72018-04-18 10:34:42 -0700104Once installed, you can upgrade to a newer version of Bazel with the following command:
Googler1fbef392017-03-22 09:05:09 +0000105
laszlocsomor79251002017-04-03 13:09:47 +0000106```bash
Clint Harrisona8e2c2e2018-11-05 10:43:21 -0800107sudo apt-get install --only-upgrade bazel
laszlocsomor79251002017-04-03 13:09:47 +0000108```