How to install mongodb on linux

Apr 24, 2022 pm 08:21 PM
linux

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
Copy after login

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         # 将解压后的文件拷贝到指定目录
Copy after login

[ Step 2] Modify the configuration file

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

sudo vi /etc/profile
Copy after login

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 = <directory>/bin:$PATH
Copy after login

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
Copy after login

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
Copy after login

[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   # 设置权限
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

See all articles