blob: 249524b91e678367fe46b02e294f4f8d348e9338 [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 macOS
4---
Googler1fbef392017-03-22 09:05:09 +00005
6# <a name="mac-os-x"></a>Install Bazel on macOS (OS X)
7
hlopko5bf297d2017-05-29 18:02:44 +02008> Note: Bazel release 0.5.0 contains a bug in the compiler detection on macOS which
9> requires Xcode and the iOS tooling to be installed
10> ([corresponding issue #3063](https://github.com/bazelbuild/bazel/issues/3063)).
11> If you had Command Line Tools installed, you also need to switch to Xcode using
12> `sudo xcode-select -s /Applications/Xcode.app/Contents/Developer`.
hlopkoe1e0f5d2017-05-29 15:34:56 +020013
Googler1fbef392017-03-22 09:05:09 +000014Install Bazel on macOS (OS X) using one of the following methods:
15
Googler18a70dc2017-05-29 16:33:17 +020016* [Use Homebrew (recommended)](#install-on-mac-os-x-homebrew)
Googler1fbef392017-03-22 09:05:09 +000017* [Use the binary installer](#install-with-installer-mac-os-x)
18* [Compile Bazel from source](install-compile-source.md)
19
20Bazel 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-mac-os-x-homebrew"></a>Install using Homebrew
26
27### 1. Install JDK 8
28
29JDK 8 can be downloaded from [Oracle's JDK
30Page](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).
Googler18a70dc2017-05-29 16:33:17 +020031
Googler1fbef392017-03-22 09:05:09 +000032Look for "Mac OS X" under "Java SE Development Kit". This will download a DMG
33image with an install wizard.
34
35### 2. Install Homebrew on macOS (OS X)
36
37Installing Homebrew is a one-time setup:
38
laszlocsomor79251002017-04-03 13:09:47 +000039```bash
40/usr/bin/ruby -e "$(curl -fsSL
41https://raw.githubusercontent.com/Homebrew/install/master/install)"
42```
Googler1fbef392017-03-22 09:05:09 +000043
44### 3. Install Bazel Homebrew Package
45
laszlocsomor79251002017-04-03 13:09:47 +000046```bash
47brew install bazel
48```
Googler1fbef392017-03-22 09:05:09 +000049
50You are all set. You can confirm Bazel is installed successfully by running
51`bazel version`.
52
53You can later upgrade to newer version of Bazel with `brew upgrade bazel`.
54
Googler18a70dc2017-05-29 16:33:17 +020055## <a name="install-with-installer-mac-os-x"></a>Install using binary installer
Googler1fbef392017-03-22 09:05:09 +000056
laurentlb3e2854b2017-05-31 16:09:26 +020057The binary installers are on Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases).
Googler1fbef392017-03-22 09:05:09 +000058
Googler18a70dc2017-05-29 16:33:17 +020059The installer contains the Bazel binary and the required JDK. Some additional
60libraries must also be installed for Bazel to work.
Googler1fbef392017-03-22 09:05:09 +000061
Googler18a70dc2017-05-29 16:33:17 +020062### 1. Install XCode command line tools
Googler1fbef392017-03-22 09:05:09 +000063
64Xcode can be downloaded from the [Apple Developer
Googler18a70dc2017-05-29 16:33:17 +020065Site](https://developer.apple.com/xcode/downloads/) (this link redirects to
66their App Store).
Googler1fbef392017-03-22 09:05:09 +000067
68For `objc_*` and `ios_*` rule support, you must have Xcode 6.1 or later with iOS
69SDK 8.1 installed on your system.
70
71Once XCode is installed you can trigger signing the license with the following
72command:
73
74```
laszlocsomor79251002017-04-03 13:09:47 +000075sudo gcc --version
Googler1fbef392017-03-22 09:05:09 +000076```
77
Googler18a70dc2017-05-29 16:33:17 +020078### 2. Download the Bazel installer
Googler1fbef392017-03-22 09:05:09 +000079
Googler18a70dc2017-05-29 16:33:17 +020080Go to Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases).
Googler1fbef392017-03-22 09:05:09 +000081
Googler18a70dc2017-05-29 16:33:17 +020082Download the binary installer `bazel-0.5.0-installer-darwin-x86_64.sh`. This
83installer contains the Bazel binary and the required JDK, and can be used even
84if a JDK is already installed.
85
86Note that `bazel-0.5.0-without-jdk-installer-darwin-x86_64.sh` is a version of
87the installer without embedded JDK 8. Only use this installer if you already
88have JDK 8 installed.
89
90Note that two other versions of the installer exist:
91* `bazel-0.5.0-without-jdk-installer-darwin-x86_64.sh`: version without
92 embedded JDK 8. Only use this installer if you already have JDK 8 installed.
93* `bazel-0.5.0-jdk7-installer-darwin-x86_64.sh`: last release compatible
94 with JDK 7.
95
96### 3. Run the installer
Googler1fbef392017-03-22 09:05:09 +000097
98Run the installer:
99
100<pre>
Googler18a70dc2017-05-29 16:33:17 +0200101chmod +x bazel-0.5.0-installer-darwin-x86_64.sh
102./bazel-0.5.0-installer-darwin-x86_64.sh --user
Googler1fbef392017-03-22 09:05:09 +0000103</pre>
104
105The `--user` flag installs Bazel to the `$HOME/bin` directory on your system and
106sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` command to see
107additional installation options.
108
Googler18a70dc2017-05-29 16:33:17 +0200109### 4. Set up your environment
Googler1fbef392017-03-22 09:05:09 +0000110
111If you ran the Bazel installer with the `--user` flag as above, the Bazel
112executable is installed in your `$HOME/bin` directory. It's a good idea to add
113this directory to your default paths, as follows:
114
115```bash
laszlocsomor79251002017-04-03 13:09:47 +0000116export PATH="$PATH:$HOME/bin"
Googler1fbef392017-03-22 09:05:09 +0000117```
118
119You can also add this command to your `~/.bashrc` file.
120
121You are all set. You can confirm Bazel is installed successfully by running
laszlocsomor79251002017-04-03 13:09:47 +0000122```bash
123bazel version
124```
Googler18a70dc2017-05-29 16:33:17 +0200125
126Once installed, you can upgrade to a newer version of Bazel with:
127
128```bash
129sudo apt-get upgrade bazel
130```