Googler | 7cd006a | 2017-03-27 14:47:34 +0000 | [diff] [blame] | 1 | --- |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 2 | layout: documentation |
Googler | 7cd006a | 2017-03-27 14:47:34 +0000 | [diff] [blame] | 3 | title: Installing Bazel on macOS |
| 4 | --- |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 5 | |
| 6 | # <a name="mac-os-x"></a>Install Bazel on macOS (OS X) |
| 7 | |
hlopko | 5bf297d | 2017-05-29 18:02:44 +0200 | [diff] [blame] | 8 | > 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`. |
hlopko | e1e0f5d | 2017-05-29 15:34:56 +0200 | [diff] [blame] | 13 | |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 14 | Install Bazel on macOS (OS X) using one of the following methods: |
| 15 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 16 | * [Use Homebrew (recommended)](#install-on-mac-os-x-homebrew) |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 17 | * [Use the binary installer](#install-with-installer-mac-os-x) |
| 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-mac-os-x-homebrew"></a>Install using Homebrew |
| 26 | |
| 27 | ### 1. Install JDK 8 |
| 28 | |
| 29 | JDK 8 can be downloaded from [Oracle's JDK |
| 30 | Page](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 31 | |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 32 | Look for "Mac OS X" under "Java SE Development Kit". This will download a DMG |
| 33 | image with an install wizard. |
| 34 | |
| 35 | ### 2. Install Homebrew on macOS (OS X) |
| 36 | |
| 37 | Installing Homebrew is a one-time setup: |
| 38 | |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 39 | ```bash |
| 40 | /usr/bin/ruby -e "$(curl -fsSL |
| 41 | https://raw.githubusercontent.com/Homebrew/install/master/install)" |
| 42 | ``` |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 43 | |
| 44 | ### 3. Install Bazel Homebrew Package |
| 45 | |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 46 | ```bash |
| 47 | brew install bazel |
| 48 | ``` |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 49 | |
| 50 | You are all set. You can confirm Bazel is installed successfully by running |
| 51 | `bazel version`. |
| 52 | |
| 53 | You can later upgrade to newer version of Bazel with `brew upgrade bazel`. |
| 54 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 55 | ## <a name="install-with-installer-mac-os-x"></a>Install using binary installer |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 56 | |
laurentlb | 3e2854b | 2017-05-31 16:09:26 +0200 | [diff] [blame] | 57 | The binary installers are on Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases). |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 58 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 59 | The installer contains the Bazel binary and the required JDK. Some additional |
| 60 | libraries must also be installed for Bazel to work. |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 61 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 62 | ### 1. Install XCode command line tools |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 63 | |
| 64 | Xcode can be downloaded from the [Apple Developer |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 65 | Site](https://developer.apple.com/xcode/downloads/) (this link redirects to |
| 66 | their App Store). |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 67 | |
| 68 | For `objc_*` and `ios_*` rule support, you must have Xcode 6.1 or later with iOS |
| 69 | SDK 8.1 installed on your system. |
| 70 | |
| 71 | Once XCode is installed you can trigger signing the license with the following |
| 72 | command: |
| 73 | |
| 74 | ``` |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 75 | sudo gcc --version |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 76 | ``` |
| 77 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 78 | ### 2. Download the Bazel installer |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 79 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 80 | Go to Bazel's [GitHub releases page](https://github.com/bazelbuild/bazel/releases). |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 81 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 82 | Download the binary installer `bazel-0.5.0-installer-darwin-x86_64.sh`. This |
| 83 | installer contains the Bazel binary and the required JDK, and can be used even |
| 84 | if a JDK is already installed. |
| 85 | |
| 86 | Note that `bazel-0.5.0-without-jdk-installer-darwin-x86_64.sh` is a version of |
| 87 | the installer without embedded JDK 8. Only use this installer if you already |
| 88 | have JDK 8 installed. |
| 89 | |
| 90 | Note 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 |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 97 | |
| 98 | Run the installer: |
| 99 | |
| 100 | <pre> |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 101 | chmod +x bazel-0.5.0-installer-darwin-x86_64.sh |
| 102 | ./bazel-0.5.0-installer-darwin-x86_64.sh --user |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 103 | </pre> |
| 104 | |
| 105 | The `--user` flag installs Bazel to the `$HOME/bin` directory on your system and |
| 106 | sets the `.bazelrc` path to `$HOME/.bazelrc`. Use the `--help` command to see |
| 107 | additional installation options. |
| 108 | |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 109 | ### 4. Set up your environment |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 110 | |
| 111 | If you ran the Bazel installer with the `--user` flag as above, the Bazel |
| 112 | executable is installed in your `$HOME/bin` directory. It's a good idea to add |
| 113 | this directory to your default paths, as follows: |
| 114 | |
| 115 | ```bash |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 116 | export PATH="$PATH:$HOME/bin" |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 117 | ``` |
| 118 | |
| 119 | You can also add this command to your `~/.bashrc` file. |
| 120 | |
| 121 | You are all set. You can confirm Bazel is installed successfully by running |
laszlocsomor | 7925100 | 2017-04-03 13:09:47 +0000 | [diff] [blame] | 122 | ```bash |
| 123 | bazel version |
| 124 | ``` |
Googler | 18a70dc | 2017-05-29 16:33:17 +0200 | [diff] [blame] | 125 | |
| 126 | Once installed, you can upgrade to a newer version of Bazel with: |
| 127 | |
| 128 | ```bash |
| 129 | sudo apt-get upgrade bazel |
| 130 | ``` |