blob: 1ea006bda04d27bd405974609604681881b236b7 [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
Googler18a70dc2017-05-29 16:33:17 +020078Go to Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases).
Googler1fbef392017-03-22 09:05:09 +000079
Googler3dd0d712017-09-26 11:39:20 -040080Download the binary installer `bazel-0.5.4-installer-linux-x86_64.sh`. This
Googler18a70dc2017-05-29 16:33:17 +020081installer contains the Bazel binary and the required JDK, and can be used even
82if JDK is already installed.
83
Googler3dd0d712017-09-26 11:39:20 -040084Note that `bazel-0.5.4-without-jdk-installer-linux-x86_64.sh` also exists.
85It is a version without embedded JDK 8. Only use this installer if you already
86have JDK 8 installed.
Googler18a70dc2017-05-29 16:33:17 +020087
88### 3. Run the installer
Googler1fbef392017-03-22 09:05:09 +000089
90Run the installer:
91
laszlocsomor79251002017-04-03 13:09:47 +000092```bash
Googler3dd0d712017-09-26 11:39:20 -040093chmod +x bazel-0.5.4-installer-linux-x86_64.sh
94./bazel-0.5.4-installer-linux-x86_64.sh --user
laszlocsomor79251002017-04-03 13:09:47 +000095```
Googler1fbef392017-03-22 09:05:09 +000096
97The `--user` flag installs Bazel to the `$HOME/bin` directory on your system and
98sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` command to see
99additional installation options.
100
Googler18a70dc2017-05-29 16:33:17 +0200101### 4. Set up your environment
Googler1fbef392017-03-22 09:05:09 +0000102
103If you ran the Bazel installer with the `--user` flag as above, the Bazel
104executable is installed in your `$HOME/bin` directory. It's a good idea to add
105this directory to your default paths, as follows:
106
107```bash
laszlocsomor79251002017-04-03 13:09:47 +0000108export PATH="$PATH:$HOME/bin"
Googler1fbef392017-03-22 09:05:09 +0000109```
110
111You can also add this command to your `~/.bashrc` file.