How to Upgrade MongoDB to Latest Stable Version


As usual with any software, old versions of MongoDB accumulate a number of security issues that if not addressed properly, could leave your data unprotected from attackers.

In order to ensure the best security and support possible, the MongoDB developers recommend to always install the latest stable version of MongoDB, which is 3.4.1 as of Feb 2017.

This guide explains:

-How to upgrade to MongoDB 3.4.1 via package manager
-How to upgrade to MongoDB 3.4.1 manually

Upgrading to MongoDB 3.4.1 via package manager
If you installed MongoDB from the MongoDB apt, yum, dnf, or zypper repositories, you should upgrade to 3.4.1 using your package manager.
Upgrading MongoDB on Ubuntu and other Debian derivatives

Debian package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command to import the MongoDB public GPG Key:

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

Create the /etc/apt/sources.list.d/mongodb-org-3.4.list file replacing ubuntu xenial with the codename appropriate for your version of Ubuntu or Debian:

$ 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

    Ubuntu 12.04: ubuntu precise
    Ubuntu 14.04: ubuntu trusty
    Ubuntu 16.04: ubuntu xenial
    Debian 7: debian wheezy
    Debian 8: debian jessie

Now issue the following command to reload the local package database and directly install the latest stable version of MongoDB:

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

Upgrading MongoDB on Amazon Linux, Red Hat Enterprise Linux, CentOS and Fedora
First of all, you need to create a /etc/yum.repos.d/mongodb-org-3.4.repo file so that yum knows where to find latest MongoDB packages. Please replace redhat/7 with the codename appropriate for your distribution and version as listed below:

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

    RHEL 5 | CentOS 5 | Fedora Core 6: redhat/5
    RHEL 6 | CentOS 6 | Fedora 12–14: redhat/6
    RHEL 7 | CentOS 7 | Fedora 19–25: redhat/7
    Amazon Linux: amazon/2013.03

Now you can simply issue the following command to install the latest version of MongoDB:

$ sudo yum install -y mongodb-org

On recent Fedora releases (>22), you may need to use dnf instead:

$ sudo dnf install -y mongodb-org

Upgrading MongoDB on SUSE, SLES and OpenSUSE
First of all, you will need to import the MongoDB public GPG Key:

$ sudo rpm --import https://www.mongodb.org/static/pgp/server-3.4.asc

Then add the MongoDB repository origin using zypper. Feel free to replace the version number 12 to match yours:

$ sudo zypper addrepo — gpgcheck “https://repo.mongodb.org/zypper/suse/12/mongodb-org/3.4/x86_64/" mongodb

Now you can simply issue the following command to install the latest version of MongoDB:

$ sudo zypper -n install mongodb-org

Upgrading MongoDB manually
If you have not installed MongoDB using a package manager, you can manually download the MongoDB binaries from the MongoDB Download Center.

For example, to download the latest release through the shell, issue the following:

$ curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.1.tgz

Then extract the files from the downloaded archive. From a system shell, you can extract through the tar command:

$ tar -zxvf mongodb-linux-x86_64-3.4.1.tgz

Now copy the extracted folder to the location from which you wish MongoDB to run:

$ mkdir -p mongodb
$ cp -R -n mongodb-linux-x86_64-3.4.1/ mongodb

The MongoDB binaries are in the bin/ directory of the archive. To ensure that the binaries are in your PATH, you can modify your PATH.

For example, you can add the following line to your shell’s rc file (e.g. ~/.bashrc):

export PATH=<mongodb-install-directory>/bin:$PATH

Remember to replace <mongodb-install-directory> with the path to the extracted MongoDB archive.

Now reload mongod and that’s all!

$ sudo service mongodb reload



{ 0 komentar... read them below or add one }

Post a Comment