Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Last active August 29, 2015 14:01
Show Gist options
  • Save bitdivine/eb7e678f14bff9df04da to your computer and use it in GitHub Desktop.
Save bitdivine/eb7e678f14bff9df04da to your computer and use it in GitHub Desktop.
Install mongodb using just shell. No package managers needed.
set -eux
INSTALLTO="${INSTALLTO:-/opt/mongodb}"
INSTALLED="$(mongo --version 2>/dev/null | sed -n '1{s/.*[^0-9.]\([0-9.]*\)/\1/g;p};q')"
LATEST="${LATEST:-$(curl -s 'http://www.mongodb.org/downloads' | sed -n 's/.*Production Release (\([0-9.]*\)).*/\1/g;ta;b;:a;p')}"
PLATFORM="${PLATFORM:-$(uname | tr A-Z a-z)}"
ARCH="${ARCH:-$(uname -m)}"
if [ "x$INSTALLED" = "x$LATEST" ]
then
echo "Latest version is already installed"
exit 0
fi
mkdir -p "$INSTALLTO"
cd "$INSTALLTO"
mkdir downloads
pushd downloads
curl -O http://downloads.mongodb.org/linux/mongodb-${PLATFORM}-${ARCH}-${LATEST}.tgz
popd
mkdir build
pushd build
cat ../downloads/mongodb-${PLATFORM}-${ARCH}-${LATEST}.tgz | gunzip | tar -x
popd
ln -s build/mongodb-${PLATFORM}-${ARCH}-${LATEST}/bin/ bin
mkdir -p /var/mongodb
ln -s /var/mongodb data
sudo apt-get install -y numactl
printf '\n%s\n' 'export PATH="$PATH:'"$INSTALLTO"'/bin"' >> ~/.bashrc
touch "$INSTALLTO"/config.yaml
# start
numactl --interleave=all "$INSTALLTO"/bin/mongod --dbpath "$INSTALLTO"/data --smallfiles --config "$INSTALLTO"/config.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment