How to install RocksDB on Ubuntu 12.04 LTS

Posted: Tháng Mười Hai 4, 2013 in Database
Thẻ:, , , , , ,

If you want to know more information about RocksDB, go to there: http://rocksdb.org/

RockDB requires some new libraries that do not support ubuntu 12.04. I’ll help you install step by step to do it.

1) Install gcc and g++ version  4.8

– Check your gcc and g++ version:

gcc --version

and

g++ --version

If gcc and g++ haven’t installed in your OS or their version < 4.7, you must install them by comand lines below:

– Add PPA to your repositories:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update

– Unistall the alternative:

sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

– Install:

sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8

– Alternative packages install:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
sudo update-alternatives --config gcc
sudo update-alternatives --config g++

at the end:

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade

2) Install the libararies:

* [zlib](http://www.zlib.net/) – a library for data compression.

sudo apt-get install zlib1g-dev

* [bzip2](http://www.bzip.org/) – a library for data compression.

sudo apt-get install libbz2-dev

* [snappy](https://code.google.com/p/snappy/) – a library for fast

     data compression.

sudo apt-get install libsnappy-dev

* [gflags](https://code.google.com/p/gflags/) – a library that handles

– Go to page: https://github.com/schuhschuh/gflags

– Download gflags compressed file.

– Extract file and cd to gflags-master folder

./configure
make
sudo make install

3) Install rocksdb:

– Download zip file from: https://github.com/facebook/rocksdb

– Extract file and cd to rocksdb-master

make
sudo make install

4) Create test project

After installing all libraries required by RocksDB. We will create a test project. In this case, I use Netbeans IDE:

1. Create an C++ Application

2. Create library

– Go to your project folder, in this project folder, we create a folder and named it as “lib”.

– Go to folder rocksdb-master that we had built and copy folder rocksdb-master/include/rocksdb to <your project folder>/lib.

– Copy library rocks-master/librocksdb.a to <your project folder>/lib and /usr/lib.

– Now make sure that you had installed bz2 and snappy. Go to /usr/lib and copy libraries: libbz2.a, libsnappy.a to <your project folder>/lib.

3. Configure your project:

Right click on Netbeans project and chose Properties.

– In Build > C++Complier > C++ Standard  chose C++11.

– In Build > C++Complier> Include Directories and Headers, link to <your project folder>/lib.

– In Build > Linker > Addition Library Directories, link to <your project folder>/lib.

– In Build > Linker > Libraries, chose Add Libraries and chose all .a files in <your project folder>/lib we had copied.

– In Build > Linker > Additional Options: add “-lz -lpthread -lrt”.

Now let’s try to copy source code below to main file in your project and build:

#include <assert.h>
#include "rocksdb/db.h"

int main(int argc, char** argv) {
 rocksdb::DB *db;
 rocksdb::Options options;
 options.create_if_missing = true;
 rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb/", &db);
 assert(status.ok());
 return 0;
}

Enjoy!

Bình luận

Bình luận về bài viết này