Skip to main content

How to Install MongoDB on Ubuntu 21.10 - Linux

 wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

 echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list


sudo apt-get update

sudo apt-get install -y mongodb-org

sudo systemctl status mongod.service


https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Directories
If you installed via the package manager, the data directory /var/lib/mongodb and the log directory /var/log/mongodb are created during the installation.
By default, MongoDB runs using the mongodb user account. If you change the user that runs the MongoDB process, you must also modify the permission to the data and log directories to give this user access to these directories.

ERROR FIX

This works for me:

  1. Stop mongod process by entering the following command in terminal: sudo systemctl stop mongod

  2. You have to make directory for "dbPath" with following command: sudo mkdir -p /data/db and sudo chown -R `id -un` /data/db

  3. Then run sudo mongod --port 27017

Done!

you can't run sudo systemctl start mongod and sudo mongod --port 27017 at same time. Stop mongod by sudo systemctl stop mongod then run sudo mongod --port 27017

Hope this solution works for all who have same problem.