1.1 Ubuntu Gnu/linux
First off, there is a version of MongoDB available in the regular Ubuntu repositories, but this version is somewhat out of date and we will be using some features that require at least version 2.x of MongoDB.
With this in mind, we will install MongoDB from the 10gen maintained repositories for Ubuntu. Most of you will be using a relatively new version of Ubuntu, which will support upstart, so we will concentrate on that.
In order to avoid GPG key errors when updating and working with software sources, we need to import the 10gen public GPG key. In a terminal window, type:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
This may fail if your internet connection is bad, but keep on trying until it succeeds. You will not be able to take advantage of automatic updates and bug fixes through apt if you do not import the key. You will, however, still be able to install MongoDB from the apt repositories.
Edit the file
and add the line
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
You should now do a
sudo apt-get update
to refresh your apt sources and download the headers.
Afterwards, you can simply install the packages with
sudo apt-get install mongodb-10gen
The service should start automatically, but if not, you can control it using Upstart in the following manner
sudo service mongodb start sudo service mongodb stop sudo service mongodb restart
If everything has gone well, you should be able to start the mongo shell with the mongo command.
If there is an issue in starting the service, you may need to manually create the
directory which Mongo defaults to using. You can also specify the directory by passing
directive to point to another directory, or configuring the dbpath in
1.2 Mac OSX
MongoDB on Mac OSX can be installed in one of two ways, using the package management tools MacPorts or Homebrew.
Using Homebrew is probably easier, as you simply need to open up a system terminal, and type in the following commands
to update your package manager,
brew install mongodb
and then, at a later stage to upgrade MongoDB
brew update brew upgrade mongodb
Installing using MacPorts is also relatively simple, but due to the fact that the code will need to be compiled on your system, it may take some time. To start the build using MacPorts issue the command
port install mongodb
Bear in mind that neither MacPorts or Homebrew come with any of the control scripts, but if your PATH is configured correctly they will be in your system path. You will need to start the mongod process manually and connect to it via mongo.
You may also choose to build MongoDB from the 10gen sources, in which case, you simply need to download, extract and fire up the mongod process, and you are ready to go!
Installing MongoDB on Windows is as simple as any of the other platforms. Please ensure that you download the latest stable version for your platform (64bit or 32bit)
MongoDB is self-contained and does not have any other system dependencies. You can run MongoDB from any folder you choose. You may install MongoDB in any directory (e.g. D:\database\mongodb)
Start up a command prompt by selecting the Start button, All Programs, Accessories and then Command Prompt. As MongoDB requires a data directory, please create one using
md data md data\db
You may then start the mongod process specifying the data directory.
If you have created your db directory in an alternative location, please use the –dbpath parameter to specify where it is
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongoDBdata"
Do not allow mongod.exe to be accessible to public networks without running in “Secure Mode” MongoDB is designed to be run in “trusted environments” and the database does not enable authentication or “Secure Mode” by default.
MongoDB can also be set up as a Windows service. First, configure the system with
Then create a configuration file for the logpath
echo logpath=C:\mongodb\log\mongo.log > C:\mongodb\mongod.cfg
Then, install and run the mongoDB service
C:\mongodb\bin\mongod.exe --config C:\mongodb\mongod.cfg --install net start MongoDB
If you have followed all of the instructions on your particular platform, ensure that you can start the MongoDB shell with the mongo command. This will connect the shell to your running local server. If your server was installed on a different server, you may connect to it by passing the IP address or fully qualified domain name of the MongoDB server into the mongo shell command. e.g.
Where 27017 is the standard port number that MongoDB process runs on.
You can always check which version of the server that you have connected to by entering
into the shell and hopefully you will see the version number of the server that you have just intstalled.