Skip to content

Instantly share code, notes, and snippets.

@srimaln91
Last active January 23, 2024 13:29
Show Gist options
  • Save srimaln91/bea81d8c5ba36a64b0cd1b3b5324f687 to your computer and use it in GitHub Desktop.
Save srimaln91/bea81d8c5ba36a64b0cd1b3b5324f687 to your computer and use it in GitHub Desktop.
Install RocksDB on Ubuntu 20.04 (Focal Fossa)
#!/bin/bash
ROCKSDB_VERSION=5.11.3
#Run as a root user
if [ "$EUID" -ne 0 ]
then echo "Please run as root (with sudo command)"
exit
fi
if ! command -v wget &> /dev/null
then
echo "wget command could not be found. installing..."
apt install -y wget
fi
if ! command -v make &> /dev/null
then
echo "make command could not be found. installing..."
apt install -y cmake
fi
if ! command -v g++ &> /dev/null
then
echo "g++ command could not be found. installing..."
apt install -y g++
fi
echo "installing required dependancies..."
sudo apt install -y libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev
echo "downloading rocksdb..."
pushd /tmp || return
wget https://github.com/facebook/rocksdb/archive/refs/tags/v${ROCKSDB_VERSION}.tar.gz
tar -xvf v${ROCKSDB_VERSION}.tar.gz && cd rocksdb-${ROCKSDB_VERSION} || return
# Ignore GCC warnings
export CXXFLAGS='-Wno-error=deprecated-copy -Wno-error=pessimizing-move -Wno-error=class-memaccess'
# Build as a shared library
make shared_lib
# The following command installs the shared library in /usr/lib/ and the header files in /usr/include/rocksdb/:
make install-shared INSTALL_PATH=/usr
popd || return
# cleanup
rm -rf /tmp/rocksdb-${ROCKSDB_VERSION} /tmp/v${ROCKSDB_VERSION}.tar.gz
echo "installation successful"
# To uninstall
#make uninstall INSTALL_PATH=/usr
@srimaln91
Copy link
Author

Thanks for pointing that out. Let me update the script. 👍

@pitigalari
Copy link

pitigalari commented May 18, 2022

Might need sudo to play with /usr/lib and /usr/include folders. So,
sudo make install-shared INSTALL_PATH=/usr

@srimaln91
Copy link
Author

@roshsoftco Thanks for the feedback. I think it's not a good practice to use sudo in scripts. We can run the script with root privileges when we execute it.

sudo ./install.sh

I have updated the script. This can be executed as a script now.

@srimaln91
Copy link
Author

Alternatively we can execute this in the following way

curl -s https://gist.githubusercontent.com/srimaln91/bea81d8c5ba36a64b0cd1b3b5324f687/raw/ba679250ebf3917203d61c60f01da5c01f441874/rocksdb-install.sh | sudo  bash

@xinmans
Copy link

xinmans commented Jan 23, 2024

Alternatively we can execute this in the following way

curl -s https://gist.githubusercontent.com/srimaln91/bea81d8c5ba36a64b0cd1b3b5324f687/raw/ba679250ebf3917203d61c60f01da5c01f441874/rocksdb-install.sh | sudo  bash

very good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment