Installing RocksDB by Compiling Source Code
There are two methods of obtaining the source code. The first method is used by default in this document.
- If the server is connected to the Internet, you can run the wget command on the server to download the source package.
- If the server is not connected to the Internet, use a browser to download the source package and upload it to the /home directory on the server.
- For details about how to obtain the source packages, see Environmental Requirements.
- Obtain the RocksDB source package.
- Download the RocksDB source package using your local browser.
https://github.com/facebook/rocksdb/archive/refs/tags/v6.10.2.tar.gz
- Copy the source package to the /home directory on the server.
If the server is connected to the Internet, you can run the wget command on the server to download the source package.
cd /home wget https://github.com/facebook/rocksdb/archive/refs/tags/v6.10.2.tar.gz mv v6.10.2.tar.gz rocksdb-6.10.2.tar.gz
- Download the RocksDB source package using your local browser.
- Go to the /home directory.
cd /home/
- Decompress the RocksDB installation package.
tar -zxvf rocksdb-6.10.2.tar.gz
- Go to the directory generated after the decompression.
cd rocksdb-6.10.2/
- Modify the CMake compilation configuration file.
vim CMakeLists.txt
If you perform the compilation based on the configuration file in the source package, when the benchmark tool is generated, an error message is displayed indicating that the required static library is not found. To solve this problem, modify the CMakeList.txt configuration file.
# Add the following content to line 1186:
add_subdirectory(third-party/gtest-1.8.1/fused-src/gtest) add_library(testharness STATIC test_util/testharness.cc) target_link_libraries(testharness gtest)
Before modification:

After modification:

- Create a directory.
mkdir build
- Go to the new directory.
cd build
- Configure the compilation.
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rocksdb -DWITH_SNAPPY=1 -DWITH_ZLIB=1 -DWITH_LZ4=1 -DWITH_ZSTD=1 -DWITH_BZ2=1 ..

- Perform the compilation.
make -j

If an error is reported during the compilation, see "Cannot allocate memory" Displayed When Compiling RocksDB.
- Perform the installation.
make install

- Move the tool to the installation directory.
cp ../utilities/merge_operators.h /usr/local/rocksdb/include/rocksdb/utilities/
mkdir -p /usr/local/rocksdb/tools
cp -p ./tools/ldb /usr/local/rocksdb/tools
cp -p ./tools/sst_dump /usr/local/rocksdb/tools
- View the installation directory.
ls /usr/local/rocksdb

- Set environment variables.
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/rocksdb/include/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/rocksdb/lib64/
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/rocksdb/lib64/
export PATH=$PATH:/usr/local/rocksdb/tools