blob: 000efb0b188cdc5619f09cd626f7a1ebdd63c253 [file] [log] [blame] [view]
David Chen8fe82a32016-08-24 10:55:41 +00001---
2layout: documentation
3title: Installing Bazel
4---
5
6# Installing Bazel
7
8Supported platforms:
9
10* [Ubuntu Linux (Wily 15.10 and Trusty 14.04 LTS)](#ubuntu)
11* [Mac OS X](#mac-os-x)
Laszlo Csomoref4e78a2016-11-24 11:03:17 +000012* [Windows (highly experimental)](#windows)
David Chen8fe82a32016-08-24 10:55:41 +000013
14For other platforms, you can try to [compile from source](#compiling-from-source).
15
16Required Java version:
17
18* Java JDK 8 or later ([JDK 7](#jdk7) is still supported
19 but deprecated).
20
21Extras:
22
23* [Bash completion](#bash)
24* [zsh completion](#zsh)
25
26For more information on using Bazel, see [Getting
27started](getting-started.html).
28
29
30## <a name="ubuntu"></a>Ubuntu
31
32Install Bazel on Ubuntu using one of the following methods:
33
Damien Martin-Guillerez671045b2016-10-11 14:17:28 +000034 * [Using our custom APT repository](#install-on-ubuntu)
David Chen8fe82a32016-08-24 10:55:41 +000035 * [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
42If you are running **Ubuntu Wily (15.10)**, you can skip this step.
43But 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
51Note: 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-Guillerez4885eef2016-10-28 12:02:50 +000057$ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
David Chen8fe82a32016-08-24 10:55:41 +000058```
59
60If 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
66Once 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
72We provide binary installers on our
73<a href="https://github.com/bazelbuild/bazel/releases">GitHub releases page</a>
74
75The 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
81install 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
89Note: 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
105Download the [Bazel installer](https://github.com/bazelbuild/bazel/releases) for
106your operating system.
107
108#### 4. Run the installer
109
110Run 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
117The `--user` flag installs Bazel to the `$HOME/bin` directory on your
118system and sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help`
119command to see additional installation options.
120
121#### 5. Set up your environment
122
123If you ran the Bazel installer with the `--user` flag as above, the Bazel
124executable is installed in your `$HOME/bin` directory. It's a good idea to add
125this directory to your default paths, as follows:
126
127```bash
128$ export PATH="$PATH:$HOME/bin"
129```
130
131You can also add this command to your `~/.bashrc` file.
132
133
134
135## <a name="mac-os-x"></a>Mac OS X
136
137Install 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
154Once 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
161We provide binary installers on our
162<a href="https://github.com/bazelbuild/bazel/releases">GitHub releases page</a>
163
164The 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
168JDK 8 can be downloaded from
169[Oracle's JDK Page](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).
170Look for "Mac OS X x64" under "Java SE Development Kit". This will download a
171DMG image with an install wizard.
172
173#### 2. Install XCode command line tools
174
175Xcode can be downloaded from the
176[Apple Developer Site](https://developer.apple.com/xcode/downloads/), which will
177redirect to the App Store.
178
179For `objc_*` and `ios_*` rule support, you must have Xcode 6.1 or later with
180iOS SDK 8.1 installed on your system.
181
182Once XCode is installed you can trigger signing the license with the following
183command:
184
185```
186$ sudo gcc --version
187```
188
189#### 3. Download Bazel
190
191Download the [Bazel installer](https://github.com/bazelbuild/bazel/releases) for
192your operating system.
193
194#### 4. Run the installer
195
196Run 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
203The `--user` flag installs Bazel to the `$HOME/bin` directory on your
204system and sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help`
205command to see additional installation options.
206
207#### 5. Set up your environment
208
209If you ran the Bazel installer with the `--user` flag as above, the Bazel
210executable is installed in your `$HOME/bin` directory. It's a good idea to add
211this directory to your default paths, as follows:
212
213```bash
214$ export PATH="$PATH:$HOME/bin"
215```
216
217You can also add this command to your `~/.bashrc` file.
218
Laszlo Csomoref4e78a2016-11-24 11:03:17 +0000219
220## <a name="windows"></a>Windows
221
222Windows support is highly experimental. Known issues are [marked with
223label "Windows"](https://github.com/bazelbuild/bazel/issues?q=is%3Aissue+is%3Aopen+label%3A%22category%3A+multi-platform+%3E+windows%22)
224on GitHub issues.
225
226We currently support only 64 bit Windows 7 or higher and we compile Bazel as a
227msys2 binary.
228
229Install 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
239You can install the unofficial package using the
240[chocolatey](https://chocolatey.org) package manager:
241
242```sh
243choco install bazel
244```
245
246This will install the latest available version of bazel, and dependencies.
247
248This package is experimental; please provide feedback to `@petemounce` in GitHub
249issue tracker. See the [Chocolatey installation and package
250maintenance](windows-chocolatey-maintenance.md) guide for more information.
251
252
253### <a name="download-binary-windows"></a>Download a precompiled binary
254
255We provide binary versions on our
256<a href="https://github.com/bazelbuild/bazel/releases">GitHub releases page</a>
257
258This is merely the Bazel binary. You'll need additional software (e.g. msys2
259shell) and some setup in your environment to run Bazel. See these requirements
260on our [Windows page](windows.md#requirements).
261
262
David Chen8fe82a32016-08-24 10:55:41 +0000263## <a name="compiling-from-source"></a>Compiling from source
264
Klaus Aehlig8d102212016-11-11 14:42:42 +0000265The standard way of compiling a release version of Bazel from source
266is to use a distribution archive. Download `bazel-<VERSION>-dist.zip`
267from
268the [release page](https://github.com/bazelbuild/bazel/releases) for
Laszlo Csomoref4e78a2016-11-24 11:03:17 +0000269the desired version (for releases 0.4.0 and earlier: download the "source
Klaus Aehlig8d102212016-11-11 14:42:42 +0000270code" zip archive and note that it will only work for the supported
271architectures as it contains binaries). We recommend to also verify
272the signature made by our
273[release key](https://bazel.build/bazel-release.pub.gpg) 48457EE0.
David Chen8fe82a32016-08-24 10:55:41 +0000274
Klaus Aehlig8d102212016-11-11 14:42:42 +0000275Unzip the archive and call `bash ./compile.sh`; this will create a
276bazel binary in `bazel-bin/src/bazel`. This binary is self-contained,
277so it can be copied to a directory on the PATH (e.g.,
David Chen8fe82a32016-08-24 10:55:41 +0000278`/usr/local/bin`) or used in-place.
279
Laszlo Csomoref4e78a2016-11-24 11:03:17 +0000280
David Chen8fe82a32016-08-24 10:55:41 +0000281## <a name="jdk7"></a>Using Bazel with JDK 7 (deprecated)
282
283Bazel version _0.1.0_ runs without any change with JDK 7. However, future
284version will stop supporting JDK 7 when our CI cannot build for it anymore.
285The 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>
289If 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
293Bazel comes with a bash completion script. To install it:
294
2951. Build it with Bazel: `bazel build //scripts:bazel-complete.bash`.
2962. 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
304Bazel also comes with a zsh completion script. To install it:
305
3061. 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
3142. 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 ```