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 | |
| 6 | # <a name="ubuntu"></a>Install Bazel on Ubuntu |
| 7 | |
| 8 | Supported Ubuntu Linux platforms: |
| 9 | |
| 10 | * 16.04 (LTS) |
Googler | c82a161 | 2017-03-28 12:56:57 +0000 | [diff] [blame] | 11 | * 14.04 (LTS) |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 12 | |
| 13 | Install Bazel on Ubuntu using one of the following methods: |
| 14 | |
| 15 | * [Use our custom APT repository (recommended)](#install-on-ubuntu) |
| 16 | * [Use the binary installer](#install-with-installer-ubuntu) |
Or Shachar | 73fe48b | 2017-05-26 14:03:57 +0200 | [diff] [blame] | 17 | * [Compile Bazel from source](install-compile-source.md) |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 18 | |
| 19 | Bazel comes with two completion scripts. After installing Bazel, you can: |
| 20 | |
| 21 | * access the [bash completion script](install.md) |
| 22 | * install the [zsh completion script](install.md) |
| 23 | |
| 24 | ## <a name="install-on-ubuntu"></a> Using Bazel custom APT repository (recommended) |
| 25 | |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 26 | ### 1. Install JDK 8 |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 27 | |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 28 | Install JDK 8 by using: |
| 29 | |
| 30 | ```bash |
| 31 | sudo apt-get install openjdk-8-jdk |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 32 | ``` |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 33 | |
| 34 | On Ubuntu 14.04 LTS you'll have to use a PPA: |
| 35 | |
| 36 | ```bash |
| 37 | sudo add-apt-repository ppa:webupd8team/java |
| 38 | sudo apt-get update && sudo apt-get install oracle-java8-installer |
| 39 | ``` |
| 40 | |
| 41 | ### 2. Add Bazel distribution URI as a package source (one time setup) |
| 42 | |
| 43 | ```bash |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 44 | echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list |
| 45 | curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 46 | ``` |
| 47 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 48 | If you want to install the testing version of Bazel, replace `stable` with |
| 49 | `testing`. |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 50 | |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 51 | ### 3. Install and update Bazel |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 52 | |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 53 | ```bash |
| 54 | sudo apt-get update && sudo apt-get install bazel |
| 55 | ``` |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 56 | |
MarkusTeufelberger | eae071c | 2017-05-17 21:58:59 +0200 | [diff] [blame] | 57 | Once installed, you can upgrade to a newer version of Bazel with: |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 58 | |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 59 | ```bash |
| 60 | sudo apt-get upgrade bazel |
| 61 | ``` |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 62 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 63 | ## <a name="install-with-installer-ubuntu"></a>Install using binary installer |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 64 | |
laurentlb | 3e2854b | 2017-05-31 16:09:26 +0200 | [diff] [blame] | 65 | The binary installers are on Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases). |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 66 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 67 | The installer contains the Bazel binary and the required JDK. Some additional |
| 68 | libraries must also be installed for Bazel to work. |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 69 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 70 | ### 1. Install required packages |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 71 | |
Thomas Broyer | d5930ea | 2017-07-10 15:29:17 +0200 | [diff] [blame] | 72 | ```bash |
hlopko | e2eb771 | 2017-08-18 13:57:00 +0200 | [diff] [blame] | 73 | sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 74 | ``` |
| 75 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 76 | ### 2. Download Bazel |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 77 | |
Googler | 67deac4 | 2017-10-26 20:34:56 +0200 | [diff] [blame^] | 78 | **Note:** In the installer file names listed in this document, replace |
| 79 | `<version>` with the appropriate Bazel version number. |
| 80 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 81 | Go to Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases). |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 82 | |
Googler | 67deac4 | 2017-10-26 20:34:56 +0200 | [diff] [blame^] | 83 | Download the binary installer `bazel-<version>-installer-linux-x86_64.sh`. This |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 84 | installer contains the Bazel binary and the required JDK, and can be used even |
| 85 | if JDK is already installed. |
| 86 | |
Googler | 67deac4 | 2017-10-26 20:34:56 +0200 | [diff] [blame^] | 87 | Note that `bazel-<version>-without-jdk-installer-linux-x86_64.sh` also exists. |
Googler | 3dd0d71 | 2017-09-26 11:39:20 -0400 | [diff] [blame] | 88 | It is a version without embedded JDK 8. Only use this installer if you already |
| 89 | have JDK 8 installed. |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 90 | |
| 91 | ### 3. Run the installer |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 92 | |
| 93 | Run the installer: |
| 94 | |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 95 | ```bash |
Googler | 67deac4 | 2017-10-26 20:34:56 +0200 | [diff] [blame^] | 96 | chmod +x bazel-<version>-installer-linux-x86_64.sh |
| 97 | ./bazel-<version>-installer-linux-x86_64.sh --user |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 98 | ``` |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 99 | |
| 100 | The `--user` flag installs Bazel to the `$HOME/bin` directory on your system and |
| 101 | sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` command to see |
| 102 | additional installation options. |
| 103 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 104 | ### 4. Set up your environment |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 105 | |
| 106 | If you ran the Bazel installer with the `--user` flag as above, the Bazel |
| 107 | executable is installed in your `$HOME/bin` directory. It's a good idea to add |
| 108 | this directory to your default paths, as follows: |
| 109 | |
| 110 | ```bash |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 111 | export PATH="$PATH:$HOME/bin" |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 112 | ``` |
| 113 | |
| 114 | You can also add this command to your `~/.bashrc` file. |