1## Compilation
2
3**Important**: If you plan to run RocksDB in production, don't compile using default
4`make` or `make all`. That will compile RocksDB in debug mode, which is much slower
5than release mode.
6
7RocksDB's library should be able to compile without any dependency installed,
8although we recommend installing some compression libraries (see below).
9We do depend on newer gcc/clang with C++11 support.
10
11There are few options when compiling RocksDB:
12
13* [recommended] `make static_lib` will compile librocksdb.a, RocksDB static library. Compiles static library in release mode.
14
15* `make shared_lib` will compile librocksdb.so, RocksDB shared library. Compiles shared library in release mode.
16
17* `make check` will compile and run all the unit tests. `make check` will compile RocksDB in debug mode.
18
19* `make all` will compile our static library, and all our tools and unit tests. Our tools
20depend on gflags. You will need to have gflags installed to run `make all`. This will compile RocksDB in debug mode. Don't
21use binaries compiled by `make all` in production.
22
23* By default the binary we produce is optimized for the platform you're compiling on
24(`-march=native` or the equivalent). SSE4.2 will thus be enabled automatically if your
25CPU supports it. To print a warning if your CPU does not support SSE4.2, build with
26`USE_SSE=1 make static_lib` or, if using CMake, `cmake -DFORCE_SSE42=ON`. If you want
27to build a portable binary, add `PORTABLE=1` before your make commands, like this:
28`PORTABLE=1 make static_lib`.
29
30## Dependencies
31
32* You can link RocksDB with following compression libraries:
33  - [zlib](http://www.zlib.net/) - a library for data compression.
34  - [bzip2](http://www.bzip.org/) - a library for data compression.
35  - [lz4](https://github.com/lz4/lz4) - a library for extremely fast data compression.
36  - [snappy](http://google.github.io/snappy/) - a library for fast
37      data compression.
38  - [zstandard](http://www.zstd.net) - Fast real-time compression
39      algorithm.
40
41* All our tools depend on:
42  - [gflags](https://gflags.github.io/gflags/) - a library that handles
43      command line flags processing. You can compile rocksdb library even
44      if you don't have gflags installed.
45
46* If you wish to build the RocksJava static target, then cmake is required for building Snappy.
47
48## Supported platforms
49
50* **Linux - Ubuntu**
51    * Upgrade your gcc to version at least 4.8 to get C++11 support.
52    * Install gflags. First, try: `sudo apt-get install libgflags-dev`
53      If this doesn't work and you're using Ubuntu, here's a nice tutorial:
54      (http://askubuntu.com/questions/312173/installing-gflags-12-04)
55    * Install snappy. This is usually as easy as:
56      `sudo apt-get install libsnappy-dev`.
57    * Install zlib. Try: `sudo apt-get install zlib1g-dev`.
58    * Install bzip2: `sudo apt-get install libbz2-dev`.
59    * Install lz4: `sudo apt-get install liblz4-dev`.
60    * Install zstandard: `sudo apt-get install libzstd-dev`.
61
62* **Linux - CentOS / RHEL**
63    * Upgrade your gcc to version at least 4.8 to get C++11 support:
64      `yum install gcc48-c++`
65    * Install gflags:
66
67              git clone https://github.com/gflags/gflags.git
68              cd gflags
69              git checkout v2.0
70              ./configure && make && sudo make install
71
72      **Notice**: Once installed, please add the include path for gflags to your `CPATH` environment variable and the
73      lib path to `LIBRARY_PATH`. If installed with default settings, the include path will be `/usr/local/include`
74      and the lib path will be `/usr/local/lib`.
75
76    * Install snappy:
77
78              sudo yum install snappy snappy-devel
79
80    * Install zlib:
81
82              sudo yum install zlib zlib-devel
83
84    * Install bzip2:
85
86              sudo yum install bzip2 bzip2-devel
87
88    * Install lz4:
89
90              sudo yum install lz4-devel
91
92    * Install ASAN (optional for debugging):
93
94              sudo yum install libasan
95
96    * Install zstandard:
97
98             wget https://github.com/facebook/zstd/archive/v1.1.3.tar.gz
99             mv v1.1.3.tar.gz zstd-1.1.3.tar.gz
100             tar zxvf zstd-1.1.3.tar.gz
101             cd zstd-1.1.3
102             make && sudo make install
103
104* **OS X**:
105    * Install latest C++ compiler that supports C++ 11:
106        * Update XCode:  run `xcode-select --install` (or install it from XCode App's settting).
107        * Install via [homebrew](http://brew.sh/).
108            * If you're first time developer in MacOS, you still need to run: `xcode-select --install` in your command line.
109            * run `brew tap homebrew/versions; brew install gcc48 --use-llvm` to install gcc 4.8 (or higher).
110    * run `brew install rocksdb`
111
112* **FreeBSD** (11.01):
113
114    * You can either install RocksDB from the Ports system using `cd /usr/ports/databases/rocksdb && make install`, or you can follow the details below to install dependencies and compile from source code:
115
116    * Install the dependencies for RocksDB:
117
118        export BATCH=YES
119        cd /usr/ports/devel/gmake && make install
120        cd /usr/ports/devel/gflags && make install
121
122        cd /usr/ports/archivers/snappy && make install
123        cd /usr/ports/archivers/bzip2 && make install
124        cd /usr/ports/archivers/liblz4 && make install
125        cd /usr/ports/archivesrs/zstd && make install
126
127        cd /usr/ports/devel/git && make install
128
129
130    * Install the dependencies for RocksJava (optional):
131
132        export BATCH=yes
133        cd /usr/ports/java/openjdk7 && make install
134
135    * Build RocksDB from source:
136        cd ~
137        git clone https://github.com/facebook/rocksdb.git
138        cd rocksdb
139        gmake static_lib
140
141    * Build RocksJava from source (optional):
142        cd rocksdb
143        export JAVA_HOME=/usr/local/openjdk7
144        gmake rocksdbjava
145
146* **OpenBSD** (6.3/-current):
147
148    * As RocksDB is not available in the ports yet you have to build it on your own:
149
150    * Install the dependencies for RocksDB:
151
152        pkg_add gmake gflags snappy bzip2 lz4 zstd git jdk bash findutils gnuwatch
153
154    * Build RocksDB from source:
155
156        cd ~
157        git clone https://github.com/facebook/rocksdb.git
158        cd rocksdb
159        gmake static_lib
160
161    * Build RocksJava from source (optional):
162
163        cd rocksdb
164        export JAVA_HOME=/usr/local/jdk-1.8.0
165        export PATH=$PATH:/usr/local/jdk-1.8.0/bin
166        gmake rocksdbjava
167
168* **iOS**:
169  * Run: `TARGET_OS=IOS make static_lib`. When building the project which uses rocksdb iOS library, make sure to define two important pre-processing macros: `ROCKSDB_LITE` and `IOS_CROSS_COMPILE`.
170
171* **Windows**:
172  * For building with MS Visual Studio 13 you will need Update 4 installed.
173  * Read and follow the instructions at CMakeLists.txt
174  * Or install via [vcpkg](https://github.com/microsoft/vcpkg)
175       * run `vcpkg install rocksdb:x64-windows`
176
177* **AIX 6.1**
178    * Install AIX Toolbox rpms with gcc
179    * Use these environment variables:
180
181             export PORTABLE=1
182             export CC=gcc
183             export AR="ar -X64"
184             export EXTRA_ARFLAGS=-X64
185             export EXTRA_CFLAGS=-maix64
186             export EXTRA_CXXFLAGS=-maix64
187             export PLATFORM_LDFLAGS="-static-libstdc++ -static-libgcc"
188             export LIBPATH=/opt/freeware/lib
189             export JAVA_HOME=/usr/java8_64
190             export PATH=/opt/freeware/bin:$PATH
191
192* **Solaris Sparc**
193    * Install GCC 4.8.2 and higher.
194    * Use these environment variables:
195
196             export CC=gcc
197             export EXTRA_CFLAGS=-m64
198             export EXTRA_CXXFLAGS=-m64
199             export EXTRA_LDFLAGS=-m64
200             export PORTABLE=1
201             export PLATFORM_LDFLAGS="-static-libstdc++ -static-libgcc"
202
203