Googler | 7cd006a | 2017-03-27 14:47:34 +0000 | [diff] [blame] | 1 | --- |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 2 | layout: documentation |
Googler | 7cd006a | 2017-03-27 14:47:34 +0000 | [diff] [blame] | 3 | title: Installing Bazel on Ubuntu |
| 4 | --- |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 5 | |
Laszlo Csomor | 7b6d2fa | 2018-10-25 07:04:33 -0700 | [diff] [blame] | 6 | <h1 id="ubuntu">Installing Bazel on Ubuntu</h1> |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 7 | |
| 8 | Supported Ubuntu Linux platforms: |
| 9 | |
Jingwen Chen | 43f792d | 2018-11-06 07:40:09 -0800 | [diff] [blame] | 10 | * 18.04 (LTS) |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 11 | * 16.04 (LTS) |
Googler | c82a161 | 2017-03-28 12:56:57 +0000 | [diff] [blame] | 12 | * 14.04 (LTS) |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 13 | |
| 14 | Install Bazel on Ubuntu using one of the following methods: |
| 15 | |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 16 | * [Use the binary installer (recommended)](#install-with-installer-ubuntu) |
| 17 | * [Use our custom APT repository](#install-on-ubuntu) |
Or Shachar | 73fe48b | 2017-05-26 14:03:57 +0200 | [diff] [blame] | 18 | * [Compile Bazel from source](install-compile-source.md) |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 19 | |
| 20 | Bazel comes with two completion scripts. After installing Bazel, you can: |
| 21 | |
Laszlo Csomor | 7b6d2fa | 2018-10-25 07:04:33 -0700 | [diff] [blame] | 22 | * Access the [bash completion script](completion.md#bash) |
| 23 | * Install the [zsh completion script](completion.md#zsh) |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 24 | |
Laszlo Csomor | 7b6d2fa | 2018-10-25 07:04:33 -0700 | [diff] [blame] | 25 | <h2 id="install-with-installer-ubuntu">Installing using binary installer</h2> |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 26 | |
| 27 | The binary installers are on Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases). |
| 28 | |
Michael Hackner | dbd6220 | 2019-04-17 08:50:42 -0700 | [diff] [blame] | 29 | The installer contains the Bazel binary. Some additional libraries must also be |
| 30 | installed for Bazel to work. |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 31 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 32 | ### Step 1: Install required packages |
| 33 | |
George Kalpakas | fa26e6e | 2018-05-02 05:21:19 -0700 | [diff] [blame] | 34 | First, install the prerequisites: `pkg-config`, `zip`, `g++`, `zlib1g-dev`, `unzip`, and `python`. |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 35 | |
| 36 | ```bash |
| 37 | sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python |
| 38 | ``` |
| 39 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 40 | ### Step 2: Download Bazel |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 41 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 42 | Next, download the Bazel binary installer named `bazel-<version>-installer-linux-x86_64.sh` |
| 43 | from the [Bazel releases page on GitHub](https://github.com/bazelbuild/bazel/releases). |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 44 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 45 | ### Step 3: Run the installer |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 46 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 47 | Run the Bazel installer as follows: |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 48 | |
| 49 | ```bash |
| 50 | chmod +x bazel-<version>-installer-linux-x86_64.sh |
| 51 | ./bazel-<version>-installer-linux-x86_64.sh --user |
| 52 | ``` |
| 53 | |
| 54 | The `--user` flag installs Bazel to the `$HOME/bin` directory on your system and |
| 55 | sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` command to see |
| 56 | additional installation options. |
| 57 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 58 | ### Step 4: Set up your environment |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 59 | |
| 60 | If you ran the Bazel installer with the `--user` flag as above, the Bazel |
| 61 | executable is installed in your `$HOME/bin` directory. It's a good idea to add |
| 62 | this directory to your default paths, as follows: |
| 63 | |
| 64 | ```bash |
| 65 | export PATH="$PATH:$HOME/bin" |
| 66 | ``` |
| 67 | |
| 68 | You can also add this command to your `~/.bashrc` file. |
| 69 | |
Laszlo Csomor | 7b6d2fa | 2018-10-25 07:04:33 -0700 | [diff] [blame] | 70 | <h2 id="install-on-ubuntu"> Using Bazel custom APT repository</h2> |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 71 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 72 | ### Step 1: Install the JDK |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 73 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 74 | Install JDK 8: |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 75 | |
| 76 | ```bash |
| 77 | sudo apt-get install openjdk-8-jdk |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 78 | ``` |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 79 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 80 | On Ubuntu 14.04 LTS you must use a PPA: |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 81 | |
| 82 | ```bash |
| 83 | sudo add-apt-repository ppa:webupd8team/java |
| 84 | sudo apt-get update && sudo apt-get install oracle-java8-installer |
| 85 | ``` |
| 86 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 87 | ### Step 2: Add Bazel distribution URI as a package source |
| 88 | |
| 89 | **Note:** This is a one-time setup step. |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 90 | |
| 91 | ```bash |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 92 | echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list |
| 93 | curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 94 | ``` |
| 95 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 96 | If you want to install the testing version of Bazel, replace `stable` with `testing`. |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 97 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 98 | ### Step 3: Install and update Bazel |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 99 | |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 100 | ```bash |
| 101 | sudo apt-get update && sudo apt-get install bazel |
| 102 | ``` |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 103 | |
spomorski | ff634f7 | 2018-04-18 10:34:42 -0700 | [diff] [blame] | 104 | Once installed, you can upgrade to a newer version of Bazel with the following command: |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 105 | |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 106 | ```bash |
Clint Harrison | a8e2c2e | 2018-11-05 10:43:21 -0800 | [diff] [blame] | 107 | sudo apt-get install --only-upgrade bazel |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 108 | ``` |