1.先按照依赖,执行以下命令
sudo apt-get install devscripts debhelper libsnappy-dev
2.下载leveldb的源码,利用wget命令
wget https://github.com/google/leveldb/archive/v1.19.zip
3. 解压,利用unzip
unzip v1.19.zip &&cd leveldb-1.19/
4. 在leveldb-1.19目录中执行 “make”,编译好leveldb,会在当前目录生成一个目录“out-shared”
5. 执行一下命令
cd ../out-shared/
sudo mv libleveldb.* /usr/local/lib
cd ../include/
sudo cp -R leveldb /usr/local/include
sudo ldconfig
执行到此,leveldb安装完成,下面来测试一下(Python)
pip install leveldb
进入到ipython环境
import leveldb db = leveldb.LevelDB('./db') # single put db.Put('hello','world') print db.Get('hello') # single delete db.Delete('hello') print db.Get('hello') # multiple put/delete applied atomically,and committed to disk batch = leveldb.WriteBatch() batch.Put('hello','world') batch.Put('hello again','world') batch.Delete('hello') db.Write(batch,sync = True)