David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 1 | --- |
| 2 | layout: documentation |
| 3 | title: Installing Bazel |
| 4 | --- |
| 5 | |
| 6 | # Installing Bazel |
| 7 | |
| 8 | Supported platforms: |
| 9 | |
| 10 | * [Ubuntu Linux (Wily 15.10 and Trusty 14.04 LTS)](#ubuntu) |
| 11 | * [Mac OS X](#mac-os-x) |
Laszlo Csomor | ef4e78a | 2016-11-24 11:03:17 +0000 | [diff] [blame] | 12 | * [Windows (highly experimental)](#windows) |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 13 | |
| 14 | For other platforms, you can try to [compile from source](#compiling-from-source). |
| 15 | |
| 16 | Required Java version: |
| 17 | |
| 18 | * Java JDK 8 or later ([JDK 7](#jdk7) is still supported |
| 19 | but deprecated). |
| 20 | |
| 21 | Extras: |
| 22 | |
| 23 | * [Bash completion](#bash) |
| 24 | * [zsh completion](#zsh) |
| 25 | |
| 26 | For more information on using Bazel, see [Getting |
| 27 | started](getting-started.html). |
| 28 | |
| 29 | |
| 30 | ## <a name="ubuntu"></a>Ubuntu |
| 31 | |
| 32 | Install Bazel on Ubuntu using one of the following methods: |
| 33 | |
Damien Martin-Guillerez | 671045b | 2016-10-11 14:17:28 +0000 | [diff] [blame] | 34 | * [Using our custom APT repository](#install-on-ubuntu) |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 35 | * [Using binary installer](#install-with-installer-ubuntu) |
| 36 | * [Compiling Bazel from source](#compiling-from-source) |
| 37 | |
| 38 | ### <a name="install-on-ubuntu"></a> Using Bazel custom API repository (recommended) |
| 39 | |
| 40 | #### 1. Install JDK 8 |
| 41 | |
| 42 | If you are running **Ubuntu Wily (15.10)**, you can skip this step. |
| 43 | But for **Ubuntu Trusty (14.04 LTS)** users, since OpenJDK 8 is not available on Trusty, please install Oracle JDK 8: |
| 44 | |
| 45 | ``` |
| 46 | $ sudo add-apt-repository ppa:webupd8team/java |
| 47 | $ sudo apt-get update |
| 48 | $ sudo apt-get install oracle-java8-installer |
| 49 | ``` |
| 50 | |
| 51 | Note: You might need to `sudo apt-get install software-properties-common` if you don't have the `add-apt-repository` command. See [here](http://manpages.ubuntu.com/manpages/wily/man1/add-apt-repository.1.html). |
| 52 | |
| 53 | #### 2. Add Bazel distribution URI as a package source (one time setup) |
| 54 | |
| 55 | ``` |
| 56 | $ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list |
Damien Martin-Guillerez | 4885eef | 2016-10-28 12:02:50 +0000 | [diff] [blame] | 57 | $ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 58 | ``` |
| 59 | |
| 60 | If you want to use the JDK 7, please replace `jdk1.8` with `jdk1.7` and if you want to install the testing version of Bazel, replace `stable` with `testing`. |
| 61 | |
| 62 | #### 3. Update and install Bazel |
| 63 | |
| 64 | `$ sudo apt-get update && sudo apt-get install bazel` |
| 65 | |
| 66 | Once installed, you can upgrade to newer version of Bazel with: |
| 67 | |
| 68 | `$ sudo apt-get upgrade bazel` |
| 69 | |
| 70 | ### <a name="install-with-installer-ubuntu"></a>Install with Installer |
| 71 | |
| 72 | We provide binary installers on our |
| 73 | <a href="https://github.com/bazelbuild/bazel/releases">GitHub releases page</a> |
| 74 | |
| 75 | The installer only contains Bazel binary, some additional libraries are required to be installed on the machine to work. |
| 76 | |
| 77 | |
| 78 | #### 1. Install JDK 8 |
| 79 | |
| 80 | **Ubuntu Trusty (14.04 LTS).** OpenJDK 8 is not available on Trusty. To |
| 81 | install Oracle JDK 8: |
| 82 | |
| 83 | ``` |
| 84 | $ sudo add-apt-repository ppa:webupd8team/java |
| 85 | $ sudo apt-get update |
| 86 | $ sudo apt-get install oracle-java8-installer |
| 87 | ``` |
| 88 | |
| 89 | Note: You might need to `sudo apt-get install software-properties-common` if you don't have the `add-apt-repository` command. See [here](http://manpages.ubuntu.com/manpages/wily/man1/add-apt-repository.1.html). |
| 90 | |
| 91 | **Ubuntu Wily (15.10).** To install OpenJDK 8: |
| 92 | |
| 93 | ``` |
| 94 | $ sudo apt-get install openjdk-8-jdk |
| 95 | ``` |
| 96 | |
| 97 | #### 2. Install other required packages |
| 98 | |
| 99 | ``` |
| 100 | $ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip |
| 101 | ``` |
| 102 | |
| 103 | #### 3. Download Bazel |
| 104 | |
| 105 | Download the [Bazel installer](https://github.com/bazelbuild/bazel/releases) for |
| 106 | your operating system. |
| 107 | |
| 108 | #### 4. Run the installer |
| 109 | |
| 110 | Run the installer: |
| 111 | |
| 112 | <pre> |
| 113 | $ chmod +x bazel-<em>version</em>-installer-<em>os</em>.sh |
| 114 | $ ./bazel-<em>version</em>-installer-<em>os</em>.sh --user |
| 115 | </pre> |
| 116 | |
| 117 | The `--user` flag installs Bazel to the `$HOME/bin` directory on your |
| 118 | system and sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` |
| 119 | command to see additional installation options. |
| 120 | |
| 121 | #### 5. Set up your environment |
| 122 | |
| 123 | If you ran the Bazel installer with the `--user` flag as above, the Bazel |
| 124 | executable is installed in your `$HOME/bin` directory. It's a good idea to add |
| 125 | this directory to your default paths, as follows: |
| 126 | |
| 127 | ```bash |
| 128 | $ export PATH="$PATH:$HOME/bin" |
| 129 | ``` |
| 130 | |
| 131 | You can also add this command to your `~/.bashrc` file. |
| 132 | |
| 133 | |
| 134 | |
| 135 | ## <a name="mac-os-x"></a>Mac OS X |
| 136 | |
| 137 | Install Bazel on Mac OS X using one of the following methods: |
| 138 | |
| 139 | * [Using Homebrew](#install-on-mac-os-x-homebrew) |
| 140 | * [Using binary installer](#install-with-installer-mac-os-x) |
| 141 | * [Compiling Bazel from source](#compiling-from-source) |
| 142 | |
| 143 | |
| 144 | ### <a name="install-on-mac-os-x-homebrew"></a>Using Homebrew |
| 145 | |
| 146 | #### 1. Install Homebrew on Mac OS X (one time setup) |
| 147 | |
| 148 | `$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"` |
| 149 | |
| 150 | #### 2. Install Bazel Homebrew Package |
| 151 | |
| 152 | `$ brew install bazel` |
| 153 | |
| 154 | Once installed, you can upgrade to newer version of Bazel with: |
| 155 | |
| 156 | `$ brew upgrade bazel` |
| 157 | |
| 158 | |
| 159 | ### <a name="install-with-installer-mac-os-x"></a>Install with installer |
| 160 | |
| 161 | We provide binary installers on our |
| 162 | <a href="https://github.com/bazelbuild/bazel/releases">GitHub releases page</a> |
| 163 | |
| 164 | The installer only contains Bazel binary, some additional libraries are required to be installed on the machine to work. |
| 165 | |
| 166 | #### 1. Install JDK 8 |
| 167 | |
| 168 | JDK 8 can be downloaded from |
| 169 | [Oracle's JDK Page](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). |
| 170 | Look for "Mac OS X x64" under "Java SE Development Kit". This will download a |
| 171 | DMG image with an install wizard. |
| 172 | |
| 173 | #### 2. Install XCode command line tools |
| 174 | |
| 175 | Xcode can be downloaded from the |
| 176 | [Apple Developer Site](https://developer.apple.com/xcode/downloads/), which will |
| 177 | redirect to the App Store. |
| 178 | |
| 179 | For `objc_*` and `ios_*` rule support, you must have Xcode 6.1 or later with |
| 180 | iOS SDK 8.1 installed on your system. |
| 181 | |
| 182 | Once XCode is installed you can trigger signing the license with the following |
| 183 | command: |
| 184 | |
| 185 | ``` |
| 186 | $ sudo gcc --version |
| 187 | ``` |
| 188 | |
| 189 | #### 3. Download Bazel |
| 190 | |
| 191 | Download the [Bazel installer](https://github.com/bazelbuild/bazel/releases) for |
| 192 | your operating system. |
| 193 | |
| 194 | #### 4. Run the installer |
| 195 | |
| 196 | Run the installer: |
| 197 | |
| 198 | <pre> |
| 199 | $ chmod +x bazel-<em>version</em>-installer-<em>os</em>.sh |
| 200 | $ ./bazel-<em>version</em>-installer-<em>os</em>.sh --user |
| 201 | </pre> |
| 202 | |
| 203 | The `--user` flag installs Bazel to the `$HOME/bin` directory on your |
| 204 | system and sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` |
| 205 | command to see additional installation options. |
| 206 | |
| 207 | #### 5. Set up your environment |
| 208 | |
| 209 | If you ran the Bazel installer with the `--user` flag as above, the Bazel |
| 210 | executable is installed in your `$HOME/bin` directory. It's a good idea to add |
| 211 | this directory to your default paths, as follows: |
| 212 | |
| 213 | ```bash |
| 214 | $ export PATH="$PATH:$HOME/bin" |
| 215 | ``` |
| 216 | |
| 217 | You can also add this command to your `~/.bashrc` file. |
| 218 | |
Laszlo Csomor | ef4e78a | 2016-11-24 11:03:17 +0000 | [diff] [blame] | 219 | |
| 220 | ## <a name="windows"></a>Windows |
| 221 | |
| 222 | Windows support is highly experimental. Known issues are [marked with |
| 223 | label "Windows"](https://github.com/bazelbuild/bazel/issues?q=is%3Aissue+is%3Aopen+label%3A%22category%3A+multi-platform+%3E+windows%22) |
| 224 | on GitHub issues. |
| 225 | |
| 226 | We currently support only 64 bit Windows 7 or higher and we compile Bazel as a |
| 227 | msys2 binary. |
| 228 | |
| 229 | Install Bazel on Windows using one of the following methods: |
| 230 | |
| 231 | * [Using Chocolatey](#install-on-windows-chocolatey) |
| 232 | * [Using binary distribution](#download-binary-windows) |
| 233 | * [Compiling Bazel from source](#compiling-from-source) -- make sure |
| 234 | your machine meets the [requirements](windows.md#requirements) |
| 235 | |
| 236 | |
| 237 | ### <a name="install-on-windows-chocolatey"></a>Install on Windows using Chocolatey |
| 238 | |
| 239 | You can install the unofficial package using the |
| 240 | [chocolatey](https://chocolatey.org) package manager: |
| 241 | |
| 242 | ```sh |
| 243 | choco install bazel |
| 244 | ``` |
| 245 | |
| 246 | This will install the latest available version of bazel, and dependencies. |
| 247 | |
| 248 | This package is experimental; please provide feedback to `@petemounce` in GitHub |
| 249 | issue tracker. See the [Chocolatey installation and package |
| 250 | maintenance](windows-chocolatey-maintenance.md) guide for more information. |
| 251 | |
| 252 | |
| 253 | ### <a name="download-binary-windows"></a>Download a precompiled binary |
| 254 | |
| 255 | We provide binary versions on our |
| 256 | <a href="https://github.com/bazelbuild/bazel/releases">GitHub releases page</a> |
| 257 | |
| 258 | This is merely the Bazel binary. You'll need additional software (e.g. msys2 |
| 259 | shell) and some setup in your environment to run Bazel. See these requirements |
| 260 | on our [Windows page](windows.md#requirements). |
| 261 | |
| 262 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 263 | ## <a name="compiling-from-source"></a>Compiling from source |
| 264 | |
Klaus Aehlig | 8d10221 | 2016-11-11 14:42:42 +0000 | [diff] [blame] | 265 | The standard way of compiling a release version of Bazel from source |
| 266 | is to use a distribution archive. Download `bazel-<VERSION>-dist.zip` |
| 267 | from |
| 268 | the [release page](https://github.com/bazelbuild/bazel/releases) for |
Laszlo Csomor | ef4e78a | 2016-11-24 11:03:17 +0000 | [diff] [blame] | 269 | the desired version (for releases 0.4.0 and earlier: download the "source |
Klaus Aehlig | 8d10221 | 2016-11-11 14:42:42 +0000 | [diff] [blame] | 270 | code" zip archive and note that it will only work for the supported |
| 271 | architectures as it contains binaries). We recommend to also verify |
| 272 | the signature made by our |
| 273 | [release key](https://bazel.build/bazel-release.pub.gpg) 48457EE0. |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 274 | |
Klaus Aehlig | 8d10221 | 2016-11-11 14:42:42 +0000 | [diff] [blame] | 275 | Unzip the archive and call `bash ./compile.sh`; this will create a |
| 276 | bazel binary in `bazel-bin/src/bazel`. This binary is self-contained, |
| 277 | so it can be copied to a directory on the PATH (e.g., |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 278 | `/usr/local/bin`) or used in-place. |
| 279 | |
Laszlo Csomor | ef4e78a | 2016-11-24 11:03:17 +0000 | [diff] [blame] | 280 | |
David Chen | 8fe82a3 | 2016-08-24 10:55:41 +0000 | [diff] [blame] | 281 | ## <a name="jdk7"></a>Using Bazel with JDK 7 (deprecated) |
| 282 | |
| 283 | Bazel version _0.1.0_ runs without any change with JDK 7. However, future |
| 284 | version will stop supporting JDK 7 when our CI cannot build for it anymore. |
| 285 | The installer for JDK 7 for Bazel versions after _0.1.0_ is labeled |
| 286 | <pre> |
| 287 | ./bazel-<em>version</em>-jdk7-installer-<em>os</em>.sh |
| 288 | </pre> |
| 289 | If you wish to use JDK 7, follow the same steps as for JDK 8 but with the _jdk7_ installer or using a different APT repository as described [here](#1-add-bazel-distribution-uri-as-a-package-source-one-time-setup). |
| 290 | |
| 291 | ## <a name="bash"></a>Getting bash completion |
| 292 | |
| 293 | Bazel comes with a bash completion script. To install it: |
| 294 | |
| 295 | 1. Build it with Bazel: `bazel build //scripts:bazel-complete.bash`. |
| 296 | 2. Copy the script `bazel-bin/scripts/bazel-complete.bash` to your |
| 297 | completion folder (`/etc/bash_completion.d` directory under Ubuntu). |
| 298 | If you don't have a completion folder, you can copy it wherever suits |
| 299 | you and simply insert `source /path/to/bazel-complete.bash` in your |
| 300 | `~/.bashrc` file (under OS X, put it in your `~/.bash_profile` file). |
| 301 | |
| 302 | ## <a name="zsh"></a>Getting zsh completion |
| 303 | |
| 304 | Bazel also comes with a zsh completion script. To install it: |
| 305 | |
| 306 | 1. Add this script to a directory on your $fpath: |
| 307 | |
| 308 | ``` |
| 309 | fpath[1,0]=~/.zsh/completion/ |
| 310 | mkdir -p ~/.zsh/completion/ |
| 311 | cp scripts/zsh_completion/_bazel ~/.zsh/completion |
| 312 | ``` |
| 313 | |
| 314 | 2. Optionally, add the following to your .zshrc. |
| 315 | |
| 316 | ``` |
| 317 | # This way the completion script does not have to parse Bazel's options |
| 318 | # repeatedly. The directory in cache-path must be created manually. |
| 319 | zstyle ':completion:*' use-cache on |
| 320 | zstyle ':completion:*' cache-path ~/.zsh/cache |
| 321 | ``` |