Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame^] | 1 | -------------------------------------------------------------------------------- |
| 2 | |
| 3 | layout: documentation |
| 4 | |
| 5 | ## title: Installing Bazel on Ubuntu |
| 6 | |
| 7 | # <a name="ubuntu"></a>Install Bazel on Ubuntu |
| 8 | |
| 9 | Supported Ubuntu Linux platforms: |
| 10 | |
| 11 | * 16.04 (LTS) |
| 12 | * 15.10 |
| 13 | |
| 14 | Install Bazel on Ubuntu using one of the following methods: |
| 15 | |
| 16 | * [Use our custom APT repository (recommended)](#install-on-ubuntu) |
| 17 | * [Use the binary installer](#install-with-installer-ubuntu) |
| 18 | * [Compile Bazel from source](#install-compile-source.md) |
| 19 | |
| 20 | Bazel comes with two completion scripts. After installing Bazel, you can: |
| 21 | |
| 22 | * access the [bash completion script](install.md) |
| 23 | * install the [zsh completion script](install.md) |
| 24 | |
| 25 | ## <a name="install-on-ubuntu"></a> Using Bazel custom APT repository (recommended) |
| 26 | |
| 27 | ### 1. Add Bazel distribution URI as a package source (one time setup) |
| 28 | |
| 29 | ``` |
| 30 | $ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list |
| 31 | $ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - |
| 32 | ``` |
| 33 | |
| 34 | If you want to use the JDK 7, please replace `jdk1.8` with `jdk1.7` and if you |
| 35 | want to install the testing version of Bazel, replace `stable` with `testing`. |
| 36 | |
| 37 | ### 2. Install and update Bazel |
| 38 | |
| 39 | `$ sudo apt-get update && sudo apt-get install bazel` |
| 40 | |
| 41 | Once installed, you can upgrade to newer version of Bazel with: |
| 42 | |
| 43 | `$ sudo apt-get upgrade bazel` |
| 44 | |
| 45 | ## <a name="install-with-installer-ubuntu"></a>Install with installer |
| 46 | |
| 47 | We provide binary installers on our |
| 48 | <a href="https://github.com/bazelbuild/bazel/releases">GitHub releases page</a> |
| 49 | |
| 50 | The installer only contains Bazel binary, some additional libraries are required |
| 51 | to be installed on the machine to work. |
| 52 | |
| 53 | ### 1. Install JDK 8 |
| 54 | |
| 55 | To install OpenJDK 8: |
| 56 | |
| 57 | ``` |
| 58 | $ sudo apt-get install openjdk-8-jdk |
| 59 | ``` |
| 60 | |
| 61 | ### 2. Install other required packages |
| 62 | |
| 63 | ``` |
| 64 | $ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip |
| 65 | ``` |
| 66 | |
| 67 | ### 3. Download Bazel |
| 68 | |
| 69 | Download the [Bazel installer](https://github.com/bazelbuild/bazel/releases) for |
| 70 | your operating system. |
| 71 | |
| 72 | ### 4. Run the installer |
| 73 | |
| 74 | Run the installer: |
| 75 | |
| 76 | <pre> |
| 77 | $ chmod +x bazel-<em>version</em>-installer-<em>os</em>.sh |
| 78 | $ ./bazel-<em>version</em>-installer-<em>os</em>.sh --user |
| 79 | </pre> |
| 80 | |
| 81 | The `--user` flag installs Bazel to the `$HOME/bin` directory on your system and |
| 82 | sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` command to see |
| 83 | additional installation options. |
| 84 | |
| 85 | ### 5. Set up your environment |
| 86 | |
| 87 | If you ran the Bazel installer with the `--user` flag as above, the Bazel |
| 88 | executable is installed in your `$HOME/bin` directory. It's a good idea to add |
| 89 | this directory to your default paths, as follows: |
| 90 | |
| 91 | ```bash |
| 92 | $ export PATH="$PATH:$HOME/bin" |
| 93 | ``` |
| 94 | |
| 95 | You can also add this command to your `~/.bashrc` file. |