Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninstall mongodb correctly and install mongodb again

Tags:

mongodb

ubuntu

Please teach me how to uninstall my mongodb in my virtualbox(ubuntu).

I tried these command and nothing was removed :

sudo apt-get purge mongodb mongodb-clients mongodb-server mongodb-dev
sudo apt-get purge mongodb-10gen
sudo apt-get autoremove

It still exists. I type mongod --version it shows db version v2.6.1

Update:

I want to remove it and then install it again:

I tried the following 4 commands -

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-org

then sudo service mongod start

and type mongo there is error:

MongoDB shell version: 2.6.4
connecting to: test
2014-09-02T21:27:10.390+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111     Connection refused
2014-09-02T21:27:10.392+0800 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

Did I miss something? Please help me. Thank you!!

like image 745
user2492364 Avatar asked Sep 02 '14 13:09

user2492364


2 Answers

Normally, with apt command, you can launch autoremove with all mongoDB packages :

sudo apt-get autoremove mongodb-*

Ok on the mongodb documentation, the packages are changed. To have an up-to-date package follow instructions :

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Create the /etc/apt/sources.list.d/mongodb.list list file using the following command:

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

Issue the following command to reload the local package database:

sudo apt-get update

And install desired packages :

sudo apt-get install mongodb-org

After that you have server, shell, mongos, ... To launch mongodb-server youcan launch the mongodb service like this :

sudo service mongod start

To connect on your local server just enter this command :

mongo
like image 87
throrin19 Avatar answered Nov 27 '22 06:11

throrin19


To remove Mongo run these commands below

sudo apt-get purge mongodb
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

If you have different versions of mongo already installed, Run the command below

sudo apt-get autoremove

To install mongo safely in Ubuntu 18.04 first update all packages by running this command

sudo apt update

Now install mongo

sudo apt install -y mongodb

Start mongo by running command below

sudo systemctl start mongodb

Now check mongodb status by running

sudo systemctl status mongodb

It should show a status Active

I hope this works for you thanks

like image 22
Banny Avatar answered Nov 27 '22 06:11

Banny