Installing MongoDB 1.8.1, in my case as a developer database, is easy. This blog post just itemises all the steps so that you can pretty much blindly follow along. I’ll probably use these steps myself as I seem to be doing this regurlarly
Download the 64bit Linux binaries from here and unzip the contents to /usr/local.
cd /tmp wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.1.tgz sudo tar -zxf /tmp/mongodb-linux-x86_64-1.8.1.tgz -C /usr/local
Setup some symbolic links.
sudo ln -s /usr/local/mongodb-linux-x86_64-1.8.1 /usr/local/mongodb sudo ln -s /usr/local/mongodb/bin/bsondump /usr/local/bin/bsondump sudo ln -s /usr/local/mongodb/bin/mongo /usr/local/bin/mongo sudo ln -s /usr/local/mongodb/bin/mongod /usr/local/bin/mongod sudo ln -s /usr/local/mongodb/bin/mongodump /usr/local/bin/mongodump sudo ln -s /usr/local/mongodb/bin/mongoexport /usr/local/bin/mongoexport sudo ln -s /usr/local/mongodb/bin/mongofiles /usr/local/bin/mongofiles sudo ln -s /usr/local/mongodb/bin/mongoimport /usr/local/bin/mongoimport sudo ln -s /usr/local/mongodb/bin/mongorestore /usr/local/bin/mongorestore sudo ln -s /usr/local/mongodb/bin/mongos /usr/local/bin/mongos sudo ln -s /usr/local/mongodb/bin/mongosniff /usr/local/bin/mongosniff sudo ln -s /usr/local/mongodb/bin/mongostat /usr/local/bin/mongostat
The first “ln -s” above sets up a handy symbolic link between the versioned mongodb folder and its unversioned counterpart. When 10Gen release updates, say version 1.8.2, all you need to do is download, unzip, and link the ’1.8.2 mongodb folder’ to the unversioned folder and ‘hey presto’ everything should just work.
To get an init script working cleanly with this setup, download mine from my Github ‘dotfiles’ repo. Please note – my init script enables journaling and the REST interface (on line 51).
wget https://github.com/ijonas/dotfiles/raw/master/etc/init.d/mongod sudo mv mongod /etc/init.d/mongod sudo chmod +x /etc/init.d/mongod
You’ll need to add a mongodb user and prep some folders
sudo useradd mongodb sudo mkdir -p /var/lib/mongodb sudo mkdir -p /var/log/mongodb sudo chown mongodb.mongodb /var/lib/mongodb sudo chown mongodb.mongodb /var/log/mongodb
Also, you need to activate your MongoDB service’s init script by adding it to your system’s run-level configuration. That way the service will startup during the boot sequence and stop nicely during the OS’ shutdown procedure.
sudo update-rc.d mongod defaults
Lastly to launch MongoDB
/etc/init.d/mongod start
Good luck!
UPDATE: Since April 6 Ubuntu now has prefabbed packages containing MongoDB 1.8.1, maintained by 10Gen. See the instruction below.
Jeezo, what’s with all the symlinks?
Why not just link the version name to a simple name like mongodb and leave it at that?
i.e.
ln -s /usr/local/mongodb-linux-x86_64-1.8.1 /usr/local/mongodb
/usr/local/mongodb/bin/bsondump
will then work etc. without creating all those links.
And you could then put /usr/local/mondgb/bin in your PATH and bsondump etc would work too.
Cheers,
-Bob T.
Thanks Bob, but I prefer my executables located /usr/local/bin rather than hacking PATH environment variables.
Or you could use the package manager
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
But I understand that its also quite nice to have it all under your own control as I do with a lot of packages …
A
Why not use Debian/Ubuntu packeges? 1.8.1 is available since 6 April.
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
sudo echo “deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen” >> /etc/apt/sources.list
sudo apt-get update
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv 7F0CEB10
sudo apt-get install
sudo apt-get install mongo-10gen
// job done
Thanks everyone pointing out the Ubuntu package route. I wasn’t aware they had been updated.
Certainly helpful
Still… I think the configuration I outline above has merit as it allows you to quickly swap between new and old versions of MongoDB by flipping a symbolic link.
I tried to update the v.1.6.5 using the Ubuntu apt-get, but it says that I have the latest version already installed… What am I missing?
Sorry for pointing this out but 10gen offers ubuntu repos that “just work”(TM) here: http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
FYI
Bye
I tried adding to change DAEMON_OPTS=”–config /etc/mongodb.conf run”, but mongodb could not be stopped. Any suggestions?
Pingback: Installing Redis 2.2.4 on Ubuntu 10.10 & 11.04 and running with an ‘init’ script.