Reinstall MongoDB Ubuntu 20.04
-
Stop the
mongodprocess by issuing the following command:-sudo service mongod stop -
Remove any MongoDB packages that you had previously installed:-
sudo apt-get purge mongodb-org* -
Remove MongoDB databases and log files:-
sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongodb -
Then reinstall MongoDB 4.4.x
-
Import the public key used by the package management system:-
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - -
The following instruction is 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 -
Update Apt
sudo apt-get update -
Install MongoDB 4.4.x (Now available 4.4.15)
sudo apt-get install -y mongodb-org=4.4.15 mongodb-org-server=4.4.15 mongodb-org-shell=4.4.15 mongodb-org-mongos=4.4.15 mongodb-org-tools=4.4.15 -
Use
mongod --versionto check if it is successfully installed -
If you encounter any error while using
mongodsudo mkdir /data cd /data sudo mkdir db sudo pkill -f mongod -
Then use sudo
mongodcommand. -
After long research, it is now working totally fine thanks to this community and Internet.
EDIT:
After following above steps:
if below error occurs:
mongod.service: Failed with result 'exit-code'.
then remove below files and start mongod service again.
sudo rm -rf /tmp/mongodb-27017.sock
sudo service mongod start
Category: Tekno