Uninstall mongodb correctly and install mongodb again - mongodb

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!!

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

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

Related

Installing MongoDB in WSL

I was trying to install MongoDB in WSL running Ubuntu 18.04 after seeing this documentation. But MongoDB says that:
IMPORTANTThe mongodb package provided by Ubuntu is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you have already installed the mongodb package on your Ubuntu system, you must first uninstall the mongodb package before proceeding with these instructions.
MongoDB also says that WSL doesn't support mongodb-org
WINDOWS SUBSYSTEM FOR LINUX (WSL) - UNSUPPORTEDMongoDB does not support the Windows Subsystem for Linux (WSL).
So, I installed mongod using sudo apt install mongodb and when I ran mongo it shows the error:
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-06-21T13:33:40.606+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017
Is there is a way to install the appropriate package and make it running?
I have come across this situation recently.
Even though MongoDB says that it is not supported in WSL, you can actually install it. So, I suggest you follow that steps given in MongoDB docs.
Note : If you have already installed mongodb please remove all those before you install mongodb-org since it may cause some issues during installation :
sudo dpkg --remove --force-remove-reinstreq mongo-tools
sudo dpkg --remove --force-remove-reinstreq mongodb-server-core
sudo apt-get --fix-broken install
For installing mongodb community edition, I have added the commands below:
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
Now, to get mongoDB running,
sudo nano /etc/init.d/mongod
and paste the contents in this link into the file and save it.
#give permissions
sudo chmod +x /etc/init.d/mongod
#start the service
sudo service mongod start
Now, you can run mongo to reach the database.
Hope it helps.
#bonyem's solution works if you try on Ubuntu 18.04 (and apparently in 19.10) but not in 20.04. WSL version should be 2 (please see this to update WSL).
You also need to "fake" the bash binary by following the steps mentioned in https://github.com/shayne/wsl2-hacks to make systemctl work.
I tried all the methods above but none of the methods worked. I came across Microsoft's official documentation and everything works like a charm.
https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-database#install-mongodb
This worked for me.
Run sudo apt install mongodb
Then after that installs run sudo service mongodb start
It will say * Starting database mongodb
And after that I can connect using mongo
Easiest way to bypass this issue is to run MongoDB on Windows. You'll still be able to connect from WSL2 over localhost.
For me, #bonyem's solution resulted in an error:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
I'm going to install Mongo 4.4. Many instructions were taken from #Lyubosumaz's directions here.
Get rid of all your Mongo PPAs.
~ ❯ sudo ls /etc/apt/sources.list.d
mongodb-org-4.4.list yarn.list
~ ❯ sudo rm -i /etc/apt/sources.list.d/mongodb-org-4.4.list
Remove all Mongo packages and bits and pieces.
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
sudo dpkg --remove --force-remove-reinstreq mongo-tools
sudo dpkg --remove --force-remove-reinstreq mongodb-org
sudo dpkg --remove --force-remove-reinstreq mongodb-org-server
sudo dpkg --remove --force-remove-reinstreq mongodb-server-core
sudo dpkg --remove --force-remove-reinstreq mongodb-org-mongos
sudo dpkg --remove --force-remove-reinstreq mongodb-org-shell
sudo dpkg --remove --force-remove-reinstreq mongodb-org-tools
sudo apt-get --fix-broken install
yes | sudo apt autoremove
Add new PPA and install Mongo 4.4.
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
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
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y mongodb-org
You'll get the same error from before. This is caused by mongodb-org package trying to use systemctl to start the DB after install (source). Notice that the same error is thrown when running the command manually.
~ ❯ sudo systemctl start mongod
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
However, running mongod should still work!
If you run into errors when running mongod, you might need to modify some permissions and create a data directory. I found the answer to these issues here, here, and here.
sudo chown $USER /tmp/mongodb-27017.sock
sudo mkdir -p /data/db
sudo chown -R $USER /data/db
I have tried some of the answers above, it did not work for me.
Then I followed a guide 1:
Update ubuntu packages
Install MongoDB on the command line
Set up your local database
Creating the folders and permissions
It worked in my case!

how to completely remove mongoDB with all instance from ubuntu

How to completely uninstall mongoDB with all its instances, and re-install it.
I've tried this,
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo apt-get autoclean
sudo apt-get autoremove
sudo apt-get purge mongodb-org*
But its giving the below error :
sudo rm -r /var/log/mongodb its giving error :rm: cannot remove
'/var/log/mongodb': No such file or directory
sudo rm -r /var/lib/mongodb its giving error :rm: cannot remove
'/var/lib/mongodb': No such file or directory
Now still, it's not removed completely.
reema#reema-s ~> mongo MongoDB shell version v4.0.11 connecting to:
mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2019-07-25T15:45:34.860+0530 E QUERY [js] Error: couldn't connect
to server 127.0.0.1:27017, connection attempt failed: SocketException:
Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused
: connect#src/mongo/shell/mongo.js:344:17 #(connect):2:6 exception:
connect failed reema#reema-s ~>
Try the below steps accordingly:
First stop the mongod process
sudo service mongod stop
Remove any MongoDB packages
sudo apt-get purge mongodb-org*
Remove MongoDB databases and log files
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
Remove MongoDB Service
sudo rm /etc/systemd/system/mongodb.service
For Ubuntu 20.04 LTS use this path sudo rm /lib/systemd/system/mongod.service
This should work for you.
In addition to the above answer you may also like to run
sudo apt-get autoremove
Sometimes if multiple versions were installed this is also required.

How to upgrade to PostgreSQL 11 for Ubuntu 18.04?

As the title suggests I want to upgrade my postgresql-10 to postgresql-11.
I'm using ubuntu-18.04.
You can follow this blog setup Postgresql-11 on Ubuntu. I found it easy and simple.
Add the PostgreSQL package repository on your Ubuntu machine
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main 11" | sudo tee /etc/apt/sources.list.d/pgsql.list
Add the GPG key of the PostgreSQL package repository:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Update APT and install postgresql-11
sudo apt update && sudo apt install postgresql-11
Upgrading Postgres to the latest version (currently 13), or to an intermediate version such as 11, should be done by running:
sudo apt install postgresql-common
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
This is documented on https://wiki.postgresql.org/wiki/Apt
This runs a bash script on your computer. See there if you wish to run the steps manually.
Once you have installed Postgres, the easiest way to upgrade on Ubuntu is with pg_upgradecluster.
Backup your data. You will dropping the database, so no games!
sudo -u postgres pg_dumpall > all.sql
Upgrade.
// Install latest Postgres. Use `postgresql-11` for v11 instead of `postgresql` for latest.
sudo apt-get install -y postgresql
// The install sets up a cluster, which needs then to be removed for the upgrade.
// Stop and remove the newly installed cluster. Use `11` instead of `13` for v11
sudo pg_dropcluster 13 main --stop
// Upgrade the db. Takes the OLD version and OLD schema as required arguments
sudo pg_upgradecluster 10 main
// Test. Once you are satisfied, remove OLD cluster.
sudo pg_dropcluster 10 main
Use this command:
sudo apt update && sudo apt install postgresql-11

Mongodb not create the process [Ubuntu machine]

I created a Ubuntu machine on a koding.com environment (like AWS EC2 Ubuntu).
That environment comes with a Mongodb 2.6 preinstalled but i need Mongo 3.0 at least, I uninstalled the 2.6 and installed the 3.2. This is What happens when i try to stop the service.
stop: Unknown instance:
myUser: ~/Web/project $
Before stop the service i started, this is what i found:
myUser: ~/Web/project $ sudo service mongod start
mongod start/running, process 5538
Also, i searched here Stop: Unknown instance mongodb (Ubuntu) without help.
Solved!
Remove files from:
/etc/apt/sources.list.d
Then:
sudo apt-get purge mongodb-org
sudo apt-get autoremove
sudo apt-get update
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Mongo DB as service on Ubuntu

I installed MongoDB on Ubuntu 14.04 using this tutorial. Everything works fine, but how can I run it as service not only manualy?
To make it more clear: I want that MongoDB keeps running after I close "ssh shell".
The easiest way is to install it via APT
Step 1: Import public key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Step 2: Add the MongoDB repository details so APT
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
Then update APT packages:
sudo apt-get update
Step 3: Installing and Verifying MongoDB
sudo apt-get install -y mongodb-org
Verify it status
service mongod status
It should show: mongod start/running, process 1611
You can also stop, start, and restart MongoDB using the service command (e.g. service mongod stop, server mongod start).
References: https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-14-04