NoCache

Table of Contents

Install the Latest Version of MongoDB on Ubuntu 20.04, 18.04, 16.04

Cyrus Kao
Last modified on .

MongoDB is one of the most popular NoSQL databases around. In this tutorial we'll be covering how to install the latest version of MongoDB Community Server from its official repository, and the following steps work for Ubuntu 20.04 LTS (Focal), 18.04 LTS (Bionic) and 16.04 LTS (Xenial).

Alternatively, you can install the specific version of MongoDB with the .deb packages provided from the official download page (not recommended):

Download page
Download page of MongoDB

Prerequisites

We'll first import the signing key from MongoDB to verify we're downloading from its official source. Then add the repository to our package lists so we can install it with apt.

Import GPG Key

Install gnupg if you don't have it on your system already:

$ sudo apt install gnupg

Import the public GPG key from MongoDB:

$ wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

Add Repository

Add the official repository to your apt package lists:

  • Ubuntu 20.04 (Focal)

    $ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
    
  • Ubuntu 18.04 (Bionic)

    $ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
    
  • Ubuntu 16.04 (Xenial)

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

Installation

Update the package lists and install mongodb-org:

$ sudo apt update
$ sudo apt install mongodb-org

Update to Latest Version

The same goes with updating. Update the package lists first, then upgrade mongodb-org if a newer version is released:

$ sudo apt update
$ sudo apt --only-upgrade install mongodb-org

Start Service

Enable and start the MongoDB service (mongod.service):

$ sudo systemctl enable --now mongod

Check if MongoDB is up and running:

$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-02-08 08:31:40 UTC; 4 days ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 892 (mongod)
     Memory: 267.6M
     CGroup: /system.slice/mongod.service
             └─892 /usr/bin/mongod --config /etc/mongod.conf
Output

See Also

Comments

Sign in to leave a comment.