I face this problem because I accidentally try to install MongoDB 3.0.x (from http://repo.mongodb.org/apt/ubuntu) while actually a MongoDB 2.6.8 (provided by ubuntu) is already installed in the same computer. Therefore, both mongod
and mongo
commands are still point to the old version (which doesn't work actually). Since the official installation document said that "You cannot install this package concurrently with the mongodb, mongodb-server, or mongodb-clients packages provided by Ubuntu", this just cannot work.
A better way is to first completely uninstalled the older version before install the new one, but I already missed that time. So
sudo apt-get purge mongodb mongodb-clients mongodb-server mongodb-dev
sudo apt-get purge mongodb-10gen
cannot remove it completely (not sure whether that's the exact case), and \usr\bin\mongo
and \usr\bin\mongod
are still point to the old mongodb (which has already been removed). Therefore, I have to manually
sudo rm /usr/bin/mongo
sudo rm /usr/bin/mongod
sudo rm /var/lib/mongodb # for the old data?
After that, there's a dpkg deadlock which shows something goes wrong, and (not sure whether I am doing right) I also removed it.
To make /usr/bin/mongo
etc point to the new mongodb, I sudo apt-get remove mongodb-org
but it only remove ~40kb things. After I reinstall it, it doesn't overwrite /usr/bin/mongo
etc. I am not sure whether that's because I used to do
beta@landlubber:~$ echo "mongodb-org hold" | sudo dpkg --set-selections
beta@landlubber:~$ echo "mongodb-org-server hold" | sudo dpkg --set-selections
beta@landlubber:~$ echo "mongodb-org-shell hold" | sudo dpkg --set-selections
beta@landlubber:~$ echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
beta@landlubber:~$ echo "mongodb-org-tools hold" | sudo dpkg --set-selections
in the installation process.
To call sudo dkpg --get-selections
, there are lines
mongodb-org hold
mongodb-org-mongos hold
mongodb-org-server hold
mongodb-org-shell hold
mongodb-org-tools hold
Their values can be changed by to install
or deinstall
by echo "mongodb-org-tools hold" | sudo dpkg --set-selections
etc, but the lines are always in there. After apt-get remove
, although apt-get
said the package has been removed, dpkg -s mongodb-org
can still give a bunch of information (which shows dpkg
still treat the packages to be installed). Therefore, here's an inconsistency between apt-get
and dpkg
.
Manually and mandatory delete the dpkg setup using
sudo dpkg --purge mongodb-org
sudo dpkg --purge mongodb-org-mongos
sudo dpkg --purge mongodb-org-server
sudo dpkg --purge mongodb-org-shell
sudo dpkg --purge mongodb-org-tools
After that, dpkg -s mongodb-org
shows that the package is not installed, and echo "mongodb-org-tools hold" | sudo dpkg --set-selections
nolonger has anything about these items. And if we sudo apt-get install -y mongodb-org
, some 50mb will be installed, and /usr/bin/mongo
and /usr/bin/mongod
will be back.
In this case, if running mongo
, the system may complain something like
2015-04-23T14:54:45.367+0800 I STORAGE In File::open(), ::open for '/home/beta/.mongorc.js' failed with errno:13 Permission denied
The ".mongorc.js" file located in your home folder could not be executed
that is because the .mongorc.js
is still the one from the old mongodb. Just remove that file and run again.