9

I have Ubuntu 16.04 machine with MongoDB 2.6.10 install.

Now I want to upgrade MongoDB to latest version, i.e., 3.4

What is the best way to Upgrade?

1 Answers1

16

You can do as following

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

$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

$ sudo apt-get update
$ sudo apt-get install -y mongodb-org

after upgrading your service will be masked. To unmask it

sudo systemctl unmask mongodb

for more detail see:

update:

If you use different ubuntu version, you should update <UBUNTU VERSION> in this command:

$ echo "deb http://repo.mongodb.org/apt/ubuntu <UBUNTU VERSION>/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

For example, if you use 18.10, change it to cosmic You can find your version with this command

$ lsb_release -a
  • show error : W: The repository 'http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 Release' does not have a Release file. N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use. N: See apt-secure(8) manpage for repository creation and user configuration details. E: Failed to fetch http://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/3.4/multiverse/binary-amd64/Packages 403 Forbidden E: Some index files failed to download. They have been ignored, or old ones used instead. – Mahdi Bagheri Oct 16 '17 at 09:18
  • 1
    @MahdiBagheri use proxy, this is blocked in iran – Mohammad Efazati Oct 16 '17 at 11:47
  • 1
    This would only work for "Ubuntu Xenial", see this article for more info: https://medium.com/mongoaudit/how-to-upgrade-mongodb-to-latest-stable-version-9607266834cf – adelriosantiago Apr 15 '19 at 21:16