This chapter introduces the installation of MongoDB and MongoDB Compass in the Linux environment (mainly including Red Hat/CentOS and Ubuntu). MongoDB has a community edition and an enterprise edition, and we usually install the community edition (MongoDB Community Edition) for free. MongoDB Compass is a visual GUI tool that makes it easy to operate MongoDB. If you don't install MongoDB Compass, you will have to operate MongoDB by typing commands.

The installation method for each Linux distribution is similar, and we will mainly introduce the installation from the compressed package below.

Installation of Dependencies for Different Linux Environments

The following are the dependencies that need to be installed in each Linux distribution.

Red Hat/CentOS Environment

64-bit versions of CentOS 6 and later

sudo yum install libcurl openssl xz-libs

Ubuntu Environment

Older versions before Ubuntu 16.04 (Xenial)

sudo apt-get install libcurl3 openssl liblzma5

Versions above Ubuntu 18.04

sudo apt-get install libcurl4 openssl liblzma4

Download MongoDB Installation Package

Official website download link:

https://www.mongodb.com/try/download/community?tck=docs_server

The download page supports MongoDB installation packages for various system versions. Select the tgz compressed package according to your system version.

Here, as an example, choose the Ubuntu 20 environment and download the corresponding tgz compressed package.

Install MongoDB on Ubuntu

Install MongoDB

Note: Here we choose the Ubuntu 20 environment. The name of the downloaded package will vary depending on your system environment and version. Remember to replace it in the installation command part.

sudo tar -zxvf mongodb-linux-x86_64-ubuntu2004-4.4.5.tgz -C /usr/local

export PATH=/usr/local/mongodb-linux-x86_64-ubuntu2004-4.4.5/bin:$PATH

sudo mkdir -p /usr/local/var/mongodb
sudo mkdir -p /usr/local/var/log/mongodb
sudo chown tizi365 /usr/local/var/mongodb
sudo chown tizi365 /usr/local/var/log/mongodb
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
ps aux | grep -v grep | grep mongod

After starting MongoDB, we can directly enter the mongo shell command line interface using the mongo command.

Install MongoDB Compass

MongoDB Compass is a visual tool for operating MongoDB, usually not installed on the server but on our personal computers. Therefore, we usually choose to install the MacOS version or the Windows version according to our personal development environment.

Official website download link:

https://www.mongodb.com/try/download/compass

Here, choose the os x system version and download the dmg installation package.

Double-click the dmg installation package to install (if you are using the Windows system, choose the windows version of the MSI installation package, and install it step by step).

Install MongoDB Compass for MacOS

Note: For instructions on how to use MongoDB Compass, please refer to the subsequent chapters.