Home>Article>Operation and Maintenance> How to install mongodb on linux

How to install mongodb on linux

青灯夜游
青灯夜游 Original
2022-04-24 20:21:40 5677browse

Installation method: 1. Download the installation package from the MongoDB official website; 2. Use tar and mv commands to extract the installation package to the specified directory; 3. Open the configuration file and add "export PATH" information; 4. Use the mkdir command to create the data storage directory and log file directory, and use the chown command to set read and write permissions.

How to install mongodb on linux

The operating environment of this tutorial: Ubuntu 18.04 system, Dell G3 computer.

Download MongoDB

Go to the MongoDB official website (https://www.mongodb.com/try/download/community) to download the appropriate installation It’s packaged, as shown in the picture below:

How to install mongodb on linux

After we select the installation package we want to use, we don’t need to download it directly in the browser, we just need to copy the download link. That’s it, then use Linux commands to download the MongoDB installation package, as shown below:

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.3.tgz

Install MongoDB

Relative to Installing MongoDB under Windows is much simpler and only requires a few simple steps to install MongoDB under Linux.

[Step 1] Unzip the downloaded installation package and move the unzipped files to the specified directory, the command is as follows:

tar -zxvf mongodb-linux-x86_64-rhel70-4.4.3.tgz # 解压 mv mongodb-src-r4.4.3 /usr/local/mongodb # 将解压后的文件拷贝到指定目录

[ Step 2] Modify the configuration file

Open the system configuration file, the command is as follows:

sudo vi /etc/profile

Next, press i or insert key in the vim editor to enter insert mode Edit the system configuration file and add the following configuration information in the configuration file:

export PATH = /bin:$PATH

where is the installation path of MongoDB, such as /usr/local/mongodb used in [Step 1], The complete configuration information is as follows:

export PATH=/usr/local/mongodb4/bin:$PATH

After editing, press the esc key to exit the insert mode, then press the shift : key and enter wq to save and exit the system configuration file.

After the system configuration file is successfully saved, you can use the following command to make the configuration file take effect:

source /etc/profile

[Step 3] Create the database directory

Default After MongoDB is started, the following two directories will be initialized:

  • Data storage directory: /var/lib/mongodb

  • Log file directory: / var/log/mongodb

So we can create these two directories and set read and write permissions before starting MongoDB, naming them as follows:

sudo mkdir -p /var/lib/mongodb sudo mkdir -p /var/log/mongodb sudo chown `whoami` /var/lib/mongodb # 设置权限 sudo chown `whoami` /var/log/mongodb # 设置权限

where mkdir -p The command is used to ensure that the directory name exists, and if it does not exist, create it. The chown `whoami` command is used to specify the file owner as the user himself, and whoami is a command to display his own name.

After completing the above steps, the MongoDB installation is complete!

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to install mongodb on linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn