Rate This Document
Findability
Accuracy
Completeness
Readability

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.
  1. Obtain the RocksDB source package.
    1. Download the RocksDB source package using your local browser.

      https://github.com/facebook/rocksdb/archive/refs/tags/v6.10.2.tar.gz

    2. 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
  2. Go to the /home directory.
    cd /home/
  3. Decompress the RocksDB installation package.
    tar -zxvf rocksdb-6.10.2.tar.gz 
  4. Go to the directory generated after the decompression.
    cd rocksdb-6.10.2/
  5. 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:

  6. Create a directory.
    mkdir build
  7. Go to the new directory.
    cd build
  8. 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 ..

  9. Perform the compilation.
    make -j

    If an error is reported during the compilation, see "Cannot allocate memory" Displayed When Compiling RocksDB.

  10. Perform the installation.
    make install

  11. 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
  12. View the installation directory.
    ls /usr/local/rocksdb

  13. 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