blob: 3da518c355a1512260e16013dc6ceea877acc476 [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
6# <a name="ubuntu"></a>Install Bazel on Ubuntu
7
8Supported Ubuntu Linux platforms:
9
10* 16.04 (LTS)
Googlerc82a1612017-03-28 12:56:57 +000011* 14.04 (LTS)
Googler1fbef392017-03-22 09:05:09 +000012
13Install 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 Shachar73fe48b2017-05-26 14:03:57 +020017* [Compile Bazel from source](install-compile-source.md)
Googler1fbef392017-03-22 09:05:09 +000018
19Bazel 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 Broyerd5930ea2017-07-10 15:29:17 +020026### 1. Install JDK 8
Googler1fbef392017-03-22 09:05:09 +000027
Thomas Broyerd5930ea2017-07-10 15:29:17 +020028Install JDK 8 by using:
29
30```bash
31sudo apt-get install openjdk-8-jdk
Googler1fbef392017-03-22 09:05:09 +000032```
Thomas Broyerd5930ea2017-07-10 15:29:17 +020033
34On Ubuntu 14.04 LTS you'll have to use a PPA:
35
36```bash
37sudo add-apt-repository ppa:webupd8team/java
38sudo 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
laszlocsomor79251002017-04-03 13:09:47 +000044echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
45curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
Googler1fbef392017-03-22 09:05:09 +000046```
47
Googler18a70dc2017-05-29 16:33:17 +020048If you want to install the testing version of Bazel, replace `stable` with
49`testing`.
Googler1fbef392017-03-22 09:05:09 +000050
Thomas Broyerd5930ea2017-07-10 15:29:17 +020051### 3. Install and update Bazel
Googler1fbef392017-03-22 09:05:09 +000052
laszlocsomor79251002017-04-03 13:09:47 +000053```bash
54sudo apt-get update && sudo apt-get install bazel
55```
Googler1fbef392017-03-22 09:05:09 +000056
MarkusTeufelbergereae071c2017-05-17 21:58:59 +020057Once installed, you can upgrade to a newer version of Bazel with:
Googler1fbef392017-03-22 09:05:09 +000058
laszlocsomor79251002017-04-03 13:09:47 +000059```bash
60sudo apt-get upgrade bazel
61```
Googler1fbef392017-03-22 09:05:09 +000062
Googler18a70dc2017-05-29 16:33:17 +020063## <a name="install-with-installer-ubuntu"></a>Install using binary installer
Googler1fbef392017-03-22 09:05:09 +000064
laurentlb3e2854b2017-05-31 16:09:26 +020065The binary installers are on Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases).
Googler1fbef392017-03-22 09:05:09 +000066
Googler18a70dc2017-05-29 16:33:17 +020067The installer contains the Bazel binary and the required JDK. Some additional
68libraries must also be installed for Bazel to work.
Googler1fbef392017-03-22 09:05:09 +000069
Googler18a70dc2017-05-29 16:33:17 +020070### 1. Install required packages
Googler1fbef392017-03-22 09:05:09 +000071
Thomas Broyerd5930ea2017-07-10 15:29:17 +020072```bash
hlopkoe2eb7712017-08-18 13:57:00 +020073sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python
Googler1fbef392017-03-22 09:05:09 +000074```
75
Googler18a70dc2017-05-29 16:33:17 +020076### 2. Download Bazel
Googler1fbef392017-03-22 09:05:09 +000077
Googler67deac42017-10-26 20:34:56 +020078**Note:** In the installer file names listed in this document, replace
79`<version>` with the appropriate Bazel version number.
80
Googler18a70dc2017-05-29 16:33:17 +020081Go to Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases).
Googler1fbef392017-03-22 09:05:09 +000082
Googler67deac42017-10-26 20:34:56 +020083Download the binary installer `bazel-<version>-installer-linux-x86_64.sh`. This
Googler18a70dc2017-05-29 16:33:17 +020084installer contains the Bazel binary and the required JDK, and can be used even
85if JDK is already installed.
86
Googler67deac42017-10-26 20:34:56 +020087Note that `bazel-<version>-without-jdk-installer-linux-x86_64.sh` also exists.
Googler3dd0d712017-09-26 11:39:20 -040088It is a version without embedded JDK 8. Only use this installer if you already
89have JDK 8 installed.
Googler18a70dc2017-05-29 16:33:17 +020090
91### 3. Run the installer
Googler1fbef392017-03-22 09:05:09 +000092
93Run the installer:
94
laszlocsomor79251002017-04-03 13:09:47 +000095```bash
Googler67deac42017-10-26 20:34:56 +020096chmod +x bazel-<version>-installer-linux-x86_64.sh
97./bazel-<version>-installer-linux-x86_64.sh --user
laszlocsomor79251002017-04-03 13:09:47 +000098```
Googler1fbef392017-03-22 09:05:09 +000099
100The `--user` flag installs Bazel to the `$HOME/bin` directory on your system and
101sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` command to see
102additional installation options.
103
Googler18a70dc2017-05-29 16:33:17 +0200104### 4. Set up your environment
Googler1fbef392017-03-22 09:05:09 +0000105
106If you ran the Bazel installer with the `--user` flag as above, the Bazel
107executable is installed in your `$HOME/bin` directory. It's a good idea to add
108this directory to your default paths, as follows:
109
110```bash
laszlocsomor79251002017-04-03 13:09:47 +0000111export PATH="$PATH:$HOME/bin"
Googler1fbef392017-03-22 09:05:09 +0000112```
113
114You can also add this command to your `~/.bashrc` file.