aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/install.md
blob: 800bcd1875fdc578eae4598dc48abb6b6a6f6751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Compiling Bazel

This file contains instructions for building and running Bazel.

## System Requirements

Supported platforms:

* Ubuntu Linux
* Mac OS X

Java:

* Java JDK 8 or later

## Getting Bazel

1. Clone the Bazel repo from GitHub:

        $ cd $HOME
        $ git clone https://github.com/google/bazel/

## Building Bazel

### Building Bazel on Ubuntu

To build Bazel on Ubuntu:

1. Install JDK 8:
  * Ubuntu Trusty (14.04LTS): OpenJDK 8 is not available so the
    fastest way is to install the Oracle JDK 8:

            $ sudo add-apt-repository ppa:webupd8team/java
            $ sudo apt-get update
            $ sudo apt-get install oracle-java8-installer
  * Ubuntu Utopic (14.10): you can install OpenJDK 8 like this:

            $ sudo apt-get install openjdk-8-jdk

2. Set the `JAVA_HOME` environment variable.

   Check if it's already set:

       $ echo $JAVA_HOME

   If this prints the path to the JDK 8 root, you can proceed to the next step.

   Otherwise you'll need to set this to the root of the JDK. Use `which javac`
   to find the path to the JDK's `bin` directory. Use `javac -version` to verify
   that you're dealing with the right JDK version.

   For example the path could be `/usr/lib/jvm/jdk1.8.0/bin/javac`. Set the
   `JAVA_HOME` variable to `/usr/lib/jvm/jdk1.8.0` then, using:

       $ export JAVA_HOME=/usr/lib/jvm/jdk1.8.0

   You can also add this line to your `~/.bashrc` file.

3. Install required packages:

        $ sudo apt-get install libarchive-dev pkg-config zip g++ zlib1g-dev

4. Build Bazel:

        $ cd bazel
        $ ./compile.sh


### Building Bazel on OS X

Using Bazel on Mac OS X requires:

* The Xcode command line tools. Xcode can be downloaded from
  [Apple's developer site](https://developer.apple.com/xcode/downloads/).
* MacPorts or Homebrew for installing required packages.
* An installation of JDK 8.
* (optional) For `objc_*` and `ios_*` rule support: An installed copy of
  Xcode 6.1 or later with iOS SDK 8.1.

To build Bazel on Mac OS X:


1. Install required packages:

        $ port install protobuf-cpp libarchive

   or

        $ brew install protobuf libarchive

2. Build Bazel:

        $ cd bazel
        $ ./compile.sh

3. Run it

        $ ./output/bazel help

## Running Bazel


The Bazel executable is located at `output/bazel` in the bazel directory.
It's a good idea to add this path to your default paths, like so (you
can also add this command to your `~/.bashrc`):

    $ export PATH="$PATH:$HOME/bazel/output/bazel"

You must run Bazel from within a source code tree that is properly
configured for use with Bazel. We call such a tree a _workspace
directory_. Bazel provides a default workspace directory with sample
`BUILD` files and source code in `base_workspace`. The default
workspace contains files and directories that must be present in order
for Bazel to work. If you want to build from source outside the
default workspace directory, copy the entire `base_workspace`
directory to the new location before adding your `BUILD` and source
files.

Build a sample Java application:

        $ cp -R $HOME/bazel/base_workspace $HOME/my_workspace
        $ cd $HOME/my_workspace
        $ bazel build //examples/java-native/src/main/java/com/example/myproject:hello-world

The build output is located in `$HOME/my_workspace/bazel-bin/examples/java-native/src/main/java/com/example/myproject/`.

Run the sample application:

    $ $HOME/my_workspace/bazel-bin/examples/java-native/src/main/java/com/example/myproject/hello-world

For more information, see [Getting started](getting-started.md).