Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

223 lines (144 sloc) 6.197 kb
=========================================
Install MongoDB on Debian or Ubuntu Linux
=========================================
.. default-domain:: mongodb
Synopsis
--------
This tutorial outlines the basic installation process for installing
:term:`MongoDB` on Ubuntu and Debian Linux systems. This tutorial uses
``.deb`` packages as the basis of the installation. 10gen publishes
packages of the MongoDB releases as ``.deb`` packages for easy
installation and management for users of Debian systems. While some of
these distributions include their own MongoDB packages, the 10gen
packages are generally more up to date.
This tutorial includes: an overview of the available packages,
instructions for configuring the package manager, the process install
packages from the 10gen repository, and preliminary MongoDB
configuration and operation.
.. seealso:: The documentation of following related processes and
concepts.
Other installation tutorials:
- :doc:`/tutorial/install-mongodb-on-redhat-centos-or-fedora-linux`
- :doc:`/tutorial/install-mongodb-on-linux`
- :doc:`/tutorial/install-mongodb-on-os-x`
.. STUB :doc:`/tutorial/install-mongodb-on-windows`
.. Documentation for getting started with MongoDB:
.. - :doc:`/getting-started`
.. - :doc:`/tutorial/insert-test-data-into-a-mongodb-database`
Package Options
---------------
The 10gen repository contains two packages:
- ``mongodb-10gen``
This package contains the latest **stable** release. Use this for
production deployments.
- ``mongodb18-10gen``
This package contains the previous stable release.
You cannot install these packages concurrently with each other or with
the ``mongodb`` package that your release of Debian or Ubuntu may
include.
Installing MongoDB
------------------
Configure Package Management System (APT)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Debian/Ubuntu package management tool (i.e. ``dpkg`` and ``apt``)
ensure package consistency and authenticity by requring that
distributors sign packages with GPG keys. Issue the following command
to import the `10gen public GPG Key </_static/10gen-gpg-key.asc>`_ as
the root user (or with ``sudo``:)
.. code-block:: sh
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Alternatively, you may use ``sudo`` to get root privileges:
.. code-block:: sh
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Edit the ``/etc/apt/sources.list`` file to include the 10gen
repository.
If you use an Ubuntu version with "Upstart" (i.e. any since version
9.10 "Karmic,") or are running with Upstart on Debian, use the
following line:
.. code-block:: sources.list
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
If you are using Debian or Ubuntu that uses SysV style init process,
use the following line:
.. code-block:: sources.list
deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen
Now issue the following command (as root or with ``sudo``) to reload
your repository:
.. code-block:: sh
apt-get update
Install Packages
~~~~~~~~~~~~~~~~
Issue the following command (as root or with ``sudo``) to install the
latest stable version of MongoDB:
.. code-block:: sh
apt-get install mongodb-10gen
When this command completes, you have successfully installed MongoDB!
Continue for configuration and start-up suggestions.
Configure MongoDB
-----------------
These packages configure MongoDB using the ``/etc/mongodb.conf`` file
in conjunction with the :term:`control script`. For Upstart-based
systems, find the control script is at ``/etc/init/mongodb.conf``. For
all other systems you can find the control script at
``/etc/init.d/mongodb``.
This MongoDB instance will store its data files in the
``/var/lib/mongodb`` and its log files in ``/var/log/mongodb``, and
run using the ``mongodb`` user account.
.. note::
If you change the user that runs the MongoDB process, you will need
to modify the access control rights to the ``/var/lib/mongodb`` and
``/var/log/mongodb`` directories.
Controlling MongoDB
--------------------
Starting MongoDB
~~~~~~~~~~~~~~~~
Upstart users can start the :program:`mongod` process by issuing the
following command:
.. code-block:: sh
sudo service mongodb start
All other users can issue the following command to start :program:`mongod`:
.. code-block:: sh
sudo /etc/init.d/mongodb start
You can verify that :program:`mongod` has started successfully by checking the
contents of the log file at ``/var/log/mongodb/mongodb.log``.
Stopping MongoDB
~~~~~~~~~~~~~~~~
Upstart users can stop the :program:`mongod` process by issuing the following
command:
.. code-block:: sh
sudo service mongodb stop
All other users can issue the following command to stop :program:`mongod`:
.. code-block:: sh
sudo /etc/init.d/mongodb stop
Restarting MongoDB
~~~~~~~~~~~~~~~~~~
Upstart users can restart the :program:`mongod` process by issuing the
following command:
.. code-block:: sh
sudo service mongodb restart
All other users can issue the following command to restart
:program:`mongod`:
.. code-block:: sh
sudo /etc/init.d/mongodb restart
Controlling :program:`mongos`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As of the current release, there are no :term:`control scripts
<control script>` for :program:`mongos`. :program:`mongos` is only
used in sharding deployments and typically do not run on the same
systems where :program:`mongod` runs. You can use the ``mongodb``
script referenced above to derive your own :program:`mongos` control
script.
Using MongoDB
-------------
Among the tools included with the MongoDB package, is the
:program:`mongo` shell. You can connect to your MongoDB instance by
issuing the following command at the system prompt:
.. code-block:: sh
mongo
This will connect to the database running on the localhost interface
by default. At the :program:`mongo` prompt, issue the following two
commands to insert a record in the "test" :term:`collection` of the
(default) "test" database.
.. code-block:: javascript
> db.test.save( { a: 1 } )
> db.test.find()
.. seealso:: ":program:`mongo`" and ":doc:`/reference/javascript`"
Jump to Line
Something went wrong with that request. Please try again.