Home » Blog » Install or uninstall Mongodb Community Server v.4.4.10 in Ubuntu 20.4 LTS (Focal)

Install or uninstall Mongodb Community Server v.4.4.10 in Ubuntu 20.4 LTS (Focal)

Follow this guide for installing Mongodb v.4.4.10 locally.

  1. Import the public Key
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
  1. Create a list file for mongodb

For Ubuntu 20.04 (Focal)

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

  1. Reload local package database
sudo apt-get update
  1. Install v.4.4.10
sudo apt-get install -y mongodb-org=4.4.10 mongodb-org-server=4.4.10 mongodb-org-shell=4.4.10 mongodb-org-mongos=4.4.10 mongodb-org-tools=4.4.10

This will install v.4.4.10

Optional. Although you can specify any available version of MongoDB, apt-get will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, you can pin the package at the currently installed version:

echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections

Run Mongodb Community Edition

  1. Start MongoDB
sudo systemctl start mongod
  1. Verify that MongoDB has started successfully.
sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo systemctl enable mongod
  1. Stop MongoDB
sudo systemctl stop mongod
  1. Restart Mongodb
sudo systemctl restart mongod
  1. Begin using MongoDB
mongo

Uninstalling Mongdb

Uninstall previous mongodb:

  1. Stop Mongodb
sudo service mongo stop
  1. Remove Mongodb Packages
sudo apt-get purge mongodb-org*

Auto remove unused packages..

sudo apt autoremove
  1. Remove Data Directories

Remove MongoDB databases and log files

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

For reference – https://docs.mongodb.com/v4.4/tutorial/install-mongodb-on-ubuntu/