First of all, let me explain that my system is Ubuntu 11.04, a 64-bit system. The following installation may need to be modified according to the system conditions.
1. Download the MongoDb installation package
$ wget
http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.0.tgz
2. Unzip
$ tar vzf mongodb-linux-x86_64-2.0.0.tgz
For the convenience of typing commands later, you can also change the name, such as mv mongodb-linux-x86_64-2.0.0.tgz
mongo2
3. Install the Python dependency package
According to the official statement, it is recommended to use pip to install MongoDb’s Python driver, but pip first depends on setuptools, so you have to check whether it is installed first.
If not, you can download and install setuptools or:
$ apt-get install python-setuptools
Note: If you are using python3.0 or above, please use the corresponding version of setuptools.
In addition, in the process of installing pip, you may need to install python-dev by the way:
$ apt-get install python-dev
4. Install pip
First download:
$ wget
http://pypi.python.org/packages/source/p/pip/pip-1.0.2.tar.gz#md5=47ec6ff3f6d962696fe08d4c8264ad49
Then unzip:
$ tar -xvf pip-1.0.2.tar.gz
Then install:
$ cd pip-1.0.2
$python setup.py install
After installing pip, you can use the command to install pymongo:
5. Install the driver for Python for Mongo
It’s simple:
$ pip install pymongo
Note that pymongo can be updated directly through pip in the future, the command is
$ pip –upgrade pymongo
6. Start the mongo service and connect
First, we create a database storage directory for mongo. www.linuxidc.com defaults to /data/db, so if there is no such directory, you have to use sudo
mkdir /data/db to create;
Of course, if you don’t want to use the default database directory, you can also specify it when starting the mongo service.
The next step is to start the service:
$./mongod –dbpath=/data/db
Note that you first need to enter the directory where mongod is located (for example, my directory is /data/mongo2/bin/mongod), and then /data/db can be replaced with the directory you want to specify.
Finally you can connect to the database in another separate window:
$./mongo
7. After the above steps are completed, you can start writing scripts with py to operate mongo.