48

Following are the commands which I used to upgrade my mongodb version from 2.6.9 to latest, but its still showing me the previous version. Let me know what I am doing wrong with the upgrading process. The problem is that mongod -version still shows the old version installed after upgrade.

Docs which I refer to - Mongodb Docs

Steps I followed -

  • sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  • 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
  • sudo apt-get update
  • sudo apt-get install -y mongodb-org

Result -

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  mongodb-org
1 upgraded, 0 newly installed, 0 to remove and 139 not upgraded.
Need to get 3,608 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://repo.mongodb.org/apt/ubuntu/ trusty/mongodb-org/3.0/multiverse mongodb-org amd64 3.0.2 [3,608 B]
Fetched 3,608 B in 0s (18.3 kB/s)      
(Reading database ... 298790 files and directories currently installed.)
Preparing to unpack .../mongodb-org_3.0.2_amd64.deb ...
arg: upgrade
Unpacking mongodb-org (3.0.2) over (2.6.9) ...
Setting up mongodb-org (3.0.2) ...

After this I re started the service - sudo service mongod restart

But still its showing me version 2.6.9 Let me know what I am doing wrong here..or missed any step ?

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
swapnesh
  • 26,318
  • 22
  • 94
  • 126

9 Answers9

67

I'm in the exact same situation, followed the exact same steps, and had the same issue.

What worked for me was:

Uninstalling:

sudo service mongod stop
sudo apt-get purge "mongodb-org*"

Do NOT remove data directories - all your data will be lost if you do.

Don't forget the quotes to prevent shell from interpreting.

Note: Calling sudo apt-get purge "mongodb-org*" deletes the mongod.conf file. In case you want to keep this file after the update, make sure you create a backup copy of it and use it after the new version has been installed.

Then install mongodb with:

sudo apt-get install -y mongodb-org

This assumes that you've already performed the previous installation steps (importing the public key, creating a list file, reloading local package database) as you've stated.

Larry Williamson
  • 1,149
  • 5
  • 18
Lior
  • 1,169
  • 1
  • 9
  • 9
  • 5
    You don't need to uninstall/purge. Instead explicitly tell the mongo installer to install the exact version you want, and it will work. There is a final step added at the end of the official docs which the OP did not do. This answer does, and it works: https://stackoverflow.com/a/34667652/404699 – steampowered Feb 04 '18 at 18:44
  • RE steampowered's comment, that "final step" was: `sudo apt-get install -y mongodb-org=3.6.23 mongodb-org-server=3.6.23 mongodb-org-shell=3.6.23 mongodb-org-mongos=3.6.23 mongodb-org-tools=3.6.23` and it was presented as an optional alternative to `sudo apt-get install -y mongodb-org`. The instructions are wrong because the latter doesn't actually install the newest version. You *must* to use the big *versioned* install command for it to work. (This is true for [the official 3.4 to 3.6 upgrade tutorial/docs](https://www.mongodb.com/docs/v3.6/tutorial/install-mongodb-on-ubuntu/), at least) – joe Jun 10 '22 at 07:06
31

[Disclaimer] Before going into upgrade consider that moving from 2.6 to 3.+ requires an update on storage files. Same if you are updating from 3.2 to 3.4 or 3.4 to 3.6. Important: You can't directly upgrade from 3.2 to 3.6, for example. You must upgrade "step by step" 3.2-->3.4-->3.6. See this question/answer for details.

This is necessary if you want to recover your old DBs

As of writing 3.6 is the latest version of MongoDB. Some details here

Beware that changing between versions also regards some syntax in .conf file.

[Procedure] A more general framework for updating is to follow the typical procedure as shown here, but point to "Install a specific release of MongoDB" part of this guide as you already have MongoDB installed.

An example on Ubuntu 14.04:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
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=3.2.18 mongodb-org-server=3.2.18 mongodb-org-shell=3.2.18 mongodb-org-mongos=3.2.18 mongodb-org-tools=3.2.18
Oliver Salzburg
  • 21,652
  • 20
  • 93
  • 138
malcolm
  • 5,486
  • 26
  • 45
  • 2
    This worked, just that 3.2.0 should be replaced with whatever version you want to install – Sharjeel Ahmed Jul 26 '17 at 08:33
  • 4
    This solution works with whatever version of Mongo and Ubuntu. And I think is way better than the other. Problem is that you need to update data from 2.6 -> 3.+ and even when stepping like this 3.2 -> 3.4 -> 3.6 I would put a disclaimer on this answer with some link: https://docs.mongodb.com/manual/release-notes/3.6-upgrade-replica-set/ – sparaflAsh Jan 17 '18 at 13:41
  • @sparaflAsh Thanks. Fell free to edit the answer and gain some reputation ;) – malcolm Jan 17 '18 at 14:05
11

Run this:

sudo apt-get update 
sudo apt-get --only-upgrade install mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
Denis Bakharev
  • 959
  • 1
  • 9
  • 7
9

You should update each package manually. So try:

dpkg -l | grep mongo

ii  mongodb-org                              3.2.10                                      amd64        MongoDB open source document-oriented database system (metapackage)
ii  mongodb-org-mongos                       3.2.10                                      amd64        MongoDB sharded cluster query router
hi  mongodb-org-server                       3.2.10                                     amd64        MongoDB database server
ii  mongodb-org-shell                        3.2.14                                     amd64        MongoDB shell client
ii  mongodb-org-tools                        3.2.14                                     amd64        MongoDB tools

and then update each pakage manually

sudo apt-get install mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools

Bogdan Guban
  • 336
  • 4
  • 4
6

You can replace binaries to upgrade to mongodb 3.0 as follows (works on Ubuntu/CentOs but commands are listed for Ubuntu) :

  1. Download tar from mongodb website as per your destribution from : https://www.mongodb.org/downloads
  2. Untar downloaded file.

    tar -zxvf {mongo-tar-file}.tgz

  3. Stop mongod service.

    sudo service mongod stop

  4. Replace binaries from your tar/bin to /usr/bin.

    cd {your-extracted-folder}/bin

    sudo mv -f * /usr/bin/

  5. Start mongod service.

    sudo service mongod start

After you connect to mongo after this, you can see version has been updated. I have upgraded in this way on my production servers without any issue.

You should backup your data before upgrading. Usually no backup/restore is necessary but sometimes things don't go as expected.

vashishatashu
  • 7,720
  • 7
  • 29
  • 34
3

Step 1: First you need to uninstall existing mongodb

  1. stop Mongodb service

    sudo service mongod stop

  2. Remove Packages.

    sudo apt-get purge mongodb-org*

  3. Remove Data Directories. (optional)

    sudo rm -r /var/log/mongodb

    sudo rm -r /var/lib/mongodb


Step 2: Then Install latest mongodb (i.e. 3.4)

1. Import the public key used by the package management system.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

2. Create a list file for MongoDB. (Ubuntu 16.04)

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

3. Reload local package database.

sudo apt-get update

4. Install the latest stable version of MongoDB

sudo apt-get install -y mongodb-org

5. Start MongoDB.

sudo service mongod start

6. Verify that MongoDB has started successfully

Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

[initandlisten] waiting for connections on port

where is the port configured in /etc/mongod.conf, 27017 by default.

Community
  • 1
  • 1
vikram eklare
  • 800
  • 7
  • 25
1

Thank. I action step by step this is done on ubuntu 14.04 LTS

Download tar from mongodb website as per your destribution from : https://www.mongodb.org/downloads Untar downloaded file.

tar -zxvf {mongo-tar-file}.tgz

Stop mongod service.

sudo service mongod stop

Replace binaries from your tar/bin to /usr/bin.

cd {your-extracted-folder}/bin

sudo mv -f * /usr/bin/

Start mongod service.

sudo service mongod start

Tony Nguyen
  • 413
  • 5
  • 11
1

In a situation we run into this issue because we still have in the /etc/apt/sources.list.d the .list file for mongodb-org's repository v4.2.

When we removed, and redone a apt update we are finally able to reeally update to 4.4 version.

realtebo
  • 23,922
  • 37
  • 112
  • 189
0

I'm getting an error each time use command sudo apt-get update. They still try to get the old version and ask pgp key for each version. The things u need to do is go to path /etc/apt/sources.list.d and delete file mongodb-org-<version>.list u need to delete after using sudo apt-get purge mongodb-org* command. Use sudo apt-get update again, it worked for me.