MongoDB is an open-source, schema-free document-oriented & cross-platform, NoSQL database. It stores data in collections of JSON-like flexible documents and used to create powerful websites and applications. MongoDB is available on default Ubuntu repositories, however the version in Ubuntu repositories are not the latest one. We need to install MongoDB package repository on Ubuntu to install the latest MongoDB package. In this post, we will guide you, MongoDB Community Edition installation steps using MongoDB package repository.
Note: MongoDB supports the 64bit platforms and also supports ARM64 and s390x architecures on select platforms only.
- Ubuntu 20.04/18.04 running instance
- sudo or root privileges
- Internet to download packages
Following are the step-by-step commands to list and remove installed MongoDB packages from Ubuntu System (Click on picture to enlarge it).
Note: Install gnupg with below command and it’s libraries if you get gnupg is not installed message on console.
[For Ubuntu 18.04]
$ sudo echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Step 3: Update Ubuntu system
$ sudo apt update
Step 4: Install MongoDB on Ubuntu
Execute the following command to install MongoDB stable version (Click on picture to enlarge it).
$ sudo apt install -y mongodb-org
Step 5: Directories and Configuration files
Followings are the data and log file location if the MongoDB is installed using package manager (Click on picture to enlarge it).
/var/lib/mongodb —> Data Directory
/var/log/mongodb —> Log Directory
/etc/mongod.conf —> Configuration file
/var/log/mongodb/mongod.log —> Log file
By default MongoDB runs with “mongodb” user. Change or modify the permission of log and data directories for mongodb user if necessary.
Step 6: Manage “mongod service”
Following commands to start|enable|restart|status|stop “mongod service”. By default “mongod.service” is stopped state, start the service shown in below (Click on picture to enlarge it).
$ systemctl start mongod.service
$ systemctl enable mongod.service
$ systemctl restart mongod.service
$ systemctl status mongod.service
$ systemctl stop mongod.service
Note: By default MongoDB is listening on port 27017
Step 8: Start using MongoDB
Access the mongo shell:
Quit from mongo shell