OPTIONS
翻译或纠错本页面

在Linux下安装MongoDB.

概述

MongoDB的编译版本为Linux提供一个简单的选择,其他Linux系统没有安装MongoDB支持包。

注意事项

安装的时候,你要看到你的生产机器是64位系统还是32位系统,然后在运行MongonDB。我们这里使用的是64位.

开始安装MongoDB.

MongoDB提供64位和32位Linux安装版本,根据自己的系统选择对应的版本。

我们这里的系统是64位,所以选择64为的安装包。

1

下载我们需要的MongoDB安装包。

MongoDB官方现在地址是‘https://www.mongodb.org/downloads

例如,你要下载版本是最新的,就在官网上找到你所需要的版本。

2

开始从官网上下载文件。

例如,你要用shell去安装,那你就要选择tar的包。

3

将下载的文件复制到你的目录。

将提取的文件夹复制到位置,MongoDB将运行。

4

确保文件path的路径正确正确。

MongoDB的安装后文件的“bin /“档案的目录。以确保路径正确,当然你可以修改自己的路径。

例如,你可以添加路径 ~/.bashrc

export PATH=<mongodb-install-directory>/bin:$PATH

< mongodb-install-directory >“替换为”“MongoDB中提取档案的路径。

在Linux下按照32位的MongoDB。

1

下载我们需要的MongoDB安装包。

MongoDB官方现在地址是‘https://www.mongodb.org/downloads

例如,你要下载版本是最新的,就在官网上找到你所需要的版本。

2

开始从官网上下载文件。

例如,你要用shell去安装,那你就要选择tar的包。

3

将下载的文件复制到你的目录。

将提取的文件夹复制到位置,MongoDB将运行。

4

确保文件path的路径正确正确。

MongoDB的安装后文件的“bin /“档案的目录。以确保路径正确,当然你可以修改自己的路径。

例如,你可以添加路径 ~/.bashrc

export PATH=<mongodb-install-directory>/bin:$PATH

< mongodb-install-directory >“替换为”“MongoDB中提取档案的路径。

Run MongoDB

1

创建数据目录。

Before you start MongoDB for the first time, create the directory to which the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a directory other than this one, you must specify that directory in the dbpath option when starting the mongod process later in this procedure.

The following example command creates the default /data/db directory:

mkdir -p /data/db
2

Set permissions for the data directory.

Before running mongod for the first time, ensure that the user account running mongod has read and write permissions for the directory.

3

Run MongoDB.

To run MongoDB, run the mongod process at the system prompt. If necessary, specify the path of the mongod or the data directory. See the following examples.

Run without specifying paths

If your system PATH variable includes the location of the mongod binary and if you use the default data directory (i.e., /data/db), simply enter mongod at the system prompt:

mongod

Specify the path of the mongod

If your PATH does not include the location of the mongod binary, enter the full path to the mongod binary at the system prompt:

<path to binary>/mongod

Specify the path of the data directory

If you do not use the default data directory (i.e., /data/db), specify the path to the data directory using the --dbpath option:

mongod --dbpath <path to data directory>
4

Stop MongoDB as needed.

To stop MongoDB, press Control+C in the terminal where the mongod instance is running.

5

Begin using MongoDB.

To begin using MongoDB, see MongoDB 快速入门. Also consider the 生产环境指南 document before deploying MongoDB in a production environment.