I want to completely uninstall MongoDB from my Ubuntu 18.04.

sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

The first two commands worked but the last two commands are not working. The following error is showing.

rm: cannot remove '/var/log/mongodb': No such file or directory  

If I hit mongod the following error shows.

bash: /usr/bin/mongod: No such file or directory  

If i hit sudo systemctl status mongodb the following error shows.

mongodb.service - High-performance, schema-free document-oriented >database
   Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2019-01-05 19:45:53 +06; 1h 3min ago
 Main PID: 18811 (code=exited, status=2)

জানু 05 19:45:53 anon-acer systemd[1]: Started High-performance, schema-free document-oriented >database.
জানু 05 19:45:53 anon-acer mongod[18811]: Error reading config file: No such file or directory
জানু 05 19:45:53 anon-acer mongod[18811]: try '/usr/bin/mongod --help' for more information
জানু 05 19:45:53 anon-acer systemd[1]: mongodb.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
জানু 05 19:45:53 anon-acer systemd[1]: mongodb.service: Failed with result 'exit-code'.  

How can I completely uninstall all of the files, configurations and everything of MongoDB from my pc?


When you purged/uninstalled MongoDB, /var/log/mongodb and /var/lib/mongodb were removed automatically. When you tried to remove those "removed" files explicitly, it threw errors,

rm: cannot remove '/var/log/mongodb': No such file or directory
bash: /usr/bin/mongod: No such file or directory              

Just because there were indeed no such files.

Moreover after you uninstalled MongoDB, there was still a file /etc/systemd/system/mongodb.service which is used to start/stop/restart MongoDB service via systemctl. Since MongoDB was already uninstalled but that file was still there and it was unable to run that service, thus showed Active: failed.

Remove that file using:

sudo rm /etc/systemd/system/mongodb.service

And you are done. Try checking its status or starting using:

sudo systemctl status mongodb
sudo systemctl start mongodb

You'll get an error like "Service not found". Now there is no service MongoDB in your system


If you need to install mongodb binary (Manually) to your Ubuntu 18.04 LTS (Bionic). You need to download mongodb .tgz file from this link .

1) Download it to your ~/Downloads folder and moveit to home directory by typing mv Downloads/mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz ~/

2) Then unter it by typing tar -zxvf mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz place it here (Home directory /home/). Dont move it from here.

3) Then make a directory at /data/db location and give write permission to thatdirectory.

sudo mkdir -p /data/db

sudo chmod -R 777 /data/db

4) Now, this is the tricky area. Make sure u r in hme directory by typing pwd (Present Working Directory)


it will show

/home/<your user name>

Then type

ls -al

This command will show up all hiddenfile at home directory and search for


5) Edit the .bashrc file and write

export PATH=mongodb-linux-x86_64-ubuntu1804-4.0.4/bin:$PATH

and save the file type source ./bashrc

Then type echo $PATH at terminal it will display ~/mongodb-linux-x86_64-ubuntu1804-4.0.4/bin:/home/xenon/.nvm/versions/node/v10.15.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

6) Now at terminal type mongo --nodb it will show MongoDB shell version v4.0.4

From here , you are all set, go ahead and enjoy mongodb installation. This istallation is bit complex but by this method you can easily control the version of mongodb and use it as per your need.

7) Then start mongod

>sudo mkdir -p /var/log && sudo chmod -R 777 /var/log
>mongod --port 27017 --dbpath /data/db --logpath /var/log/local.log --fork
>mongo --port 27017

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.