Upgrading MongoDB 3.4 to 3.6 on Ubuntu 16.04: Easy as Microwave Pie

by | May 16, 2018

MongoDB 3.6 has some awesome features, change streams being my personal favourite (see all the changes here), but what if we have an old MongoDB cluster running on 3.4 and want to use these cool features? Here is how!
Note: This guide assumes you installed MongoDB from the package management system as seen here or as a replica set as seen here.

Upgrading MongoDB 3.4 to 3.6 on Ubuntu 16.04

Step 1: Stop the old Mongod server

Easy just run “sudo systemctl stop mongod” and MongoDB will be stopped.

Step 2: Import the MongoDB public key

Run “sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5” and the key is imported for you!

Step 3: Update the list file for apt/MongoDB

To remove the old list run “sudo rm /etc/apt/sources.list.d/mongodb-org-3.4.list
Now add the new one with
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
Run “sudo apt-get update” to update apt’s lists.

Step 4: Upgrade the MongoDB install

The easiest way to do this is to run “sudo apt-get upgrade -y” which will make apt update all the out of date packages in your system. Fun!
If it asks to replace the file at /etc/mongod.conf just say no to keep your settings as they are.

Step 5: Start MongoDB

Run “sudo systemctl start mongod” and we are up and running. It’s as easy as that!
Just like that, you have a MongoDB 3.6 install working! This works for replica set’s as well, just upgrade each node in turn!
Until next time
Tim Gray
Coffee to Code

Read Tim’s other blog posts about Why we switched to MongoDB, How to Install MongoDB, and all the other cool tech we use here.

We run regular business intelligence courses in both Wellington and Auckland. Come along to learn more about how we do what we do.

  1. DA Test

    Thanks for the straightforward instructions! However please check the quotes in the command to add the new list file:
    echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
    The quotes around the deb…multiverse part must be the plain double quotes, not styled ones, otherwise they will not be parsed correctly. So for readers copy-pasting commands, need to be careful to replace the quote characters in this command.

  2. Tim Gray

    Thanks for the feedback! That section has been updated.

  3. shimon Brandsdorfer

    What I needed to do is to add –allow-authentication with the upgrade. like this:
    sudo apt-get upgrade -y –allow-authentication

  4. Jim Bridger

    definitely not as easy as microwave pie, since it took me like 10 tries to get it to work, but it eventually did, and I was able to upgrade to 4.0 afterwards, so thank you, since it’s extremely confusing to upgrade software on linux and very few good walkthroughs online (at least that are findable with google)

  5. Tim Gray

    Hi Jim
    Sorry to hear you did find it as easy as we did. Glad to hear that we were able to be of some assistance and that you got it working in the end!

Leave a Reply to DA Test Cancel reply

Your email address will not be published. Required fields are marked *