• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WPArena

WPArena

WPArena is a premium online resource site of WordPress and is focused on providing excellent WordPress Tutorials, Guides, Tips, and Collections.

  • News
    • Opinion
  • Tutorials
  • Reviews
    • Themes
    • Plugins
  • Comparisons
  • Collections
    • Education Themes
    • Genesis Child Themes
    • Best Responsive Themes
    • Medical WordPress Themes
    • Finance & Business Themes
    • Crowdfunding Themes
  • Resources
    • Inspiration
  • Services
WPArena » Tutorials
Tutorials

How to install MongoDB on Ubuntu Server 18.04

Avatar of Editorial Staff Editorial Staff Updated: December 21, 2020

mongoDB on ubuntu server
FacebookTweetPinLinkedInEmailPrint

If your company is in the business of using, handling or depending on data, chances are you’re in need of a document-oriented, NoSQL database. If you’re unfamiliar with the term, a NoSQL database is a non-relational database that doesn’t use tables filled with rows and columns. Instead, they make use of a storage model that is optimized specifically for the data.

These types of databases offer scalability, flexibility, data distribution, and speed of processing that relational databases can’t match.

One NoSQL database is MongoDB. This database has been adopted by big data and enterprise companies including Adobe, Craigslist, eBay, FIFA, Foursquare, and LinkedIn. MongoDB comes in both an enterprise and community edition. I’ll be demonstrating with the open-source community edition, installing it on Ubuntu Server 18.04.

This edition can be installed from the standard repositories, however, that will likely install an outdated version. Because of that, I’ll show how to deploy a version from the official MongoDB repository. This will install:

  • mongodb-org (this is the meta-package that will install everything below)
  • mongodb-org-server (the mongod daemon)
  • mongodb-org-mongos (the mongos daemon)
  • mongodb-org-shell (the mongo shell)
  • mongodb-org-tools (the MongoDB tools package which includes import, dump, export, files, performance, restore, and stats tools)

Do note that this package only supports 64-bit architecture and LTS (Long Term Support) versions of Ubuntu (so 14.04, 16.04, and 18.04).

Once installed, your Java development company (or whatever sector your business serves) can begin developing for big data.

Update/Upgrade

When installing a major application/service, it’s always best to first run an update/upgrade on the server. Not only will this ensure you have the most recent software, but it’ll also apply any security patches. Do note, however, that should the kernel be updated in this process, you will need to reboot the machine before the updates take effect.

To update and upgrade Ubuntu, log into the server, and issue the following two commands:

sudo apt-get update
sudo apt-get upgrade -y

Once up the update and upgrade completes, reboot your server (if required). You are now ready to install MongoDB, and you won’t even need to bring in your Java developers to take care of this task.

Adding the Repository

The first thing to be done is the addition of the necessary MongoDB repository. To do this, log into your Ubuntu server. From the command line, add the required MongoDB key with the command:

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

If you see an error regarding the wget command, install that tool with:

sudo apt-get install wget

Once you’ve added the key, create a new apt source list file with the command:

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list

Installation

Now it’s time to install MongoDB. Update apt with the command:

sudo apt-get update

Once apt is updated, install MongoDB with the command:

sudo apt-get install mongodb-org -y

Starting and Enabling the Community Edition

With the database installed, you’ll want to start and enable it to run upon server reboot. Otherwise, you’ll have to manually start it every time the server is restarted.

To start the MongoDB database engine, issue the command:

sudo systemctl start mongod

You’ll then want to enable MongoDB with the command:

sudo systemctl enable mongod

Using MongoDB

In order to start working with Mongo, issue the command:

mongo

If you get an error status 62, it means that the version of MongoDB is too new for your server. If that’s the case, you’ll need to uninstall the latest version and install the version from the official Ubuntu repositories. Here are the steps for that process:

  1. Remove the latest version with the command sudo apt-get purge mongodb-org.
  2. Remove any extra dependencies with the command sudo apt-get autoremove.
  3. Install the older version of MongoDB with the command sudo apt-get install mongodb -y.

At this point, you should then have access to the MongoDB command prompt (Figure 1) by issuing the mongo command.

Figure 1

The MongoDB command prompt.

Let’s say you want to create a new database. Unlike relational databases, you don’t use the CREATE command. Instead, you simply issue the use command like so:

use DATABASE

Where DATABASE is the name of the database to be created.

This doesn’t actually create the database. In order to finalize that, you must insert data into the new database. Say you create a database named albums. You can then insert data into that database with the command:

db.artists.insert({artistname: "Devin Townsend" })

The above command would insert the string “Devin Townsend” associated with artistname in the database albums. You should see WriteResult({ “nInserted” : 1 }) as a result (Figure 2).

Figure 2

Successfully insertion of data into the new db.

And that’s all there is to installing MongoDB on Ubuntu 18.04 and creating your first database. For more information on using MongoDB, make sure to read the official documentation for the release you’ve installed.

This post was orginally published on: January 22, 2020 and was updated on: December 21, 2020.

Related Tags: MongoDB Ubuntu Ubuntu 18.04

FacebookTweetPinLinkedInEmailPrint

Related Stories

  • How To Add a PayPal Donate Button To WordPress Blog

    How To Add a PayPal Donate Button To WordPress Blog

  • How To Add MyBlogLog Widget To A WordPress Blog

    How To Add MyBlogLog Widget To A WordPress Blog

  • How to Add/Show Category Images in WordPress

Avatar of Editorial Staff

Editorial Staff

Editorial Staff at WPArena is a team of WordPress experts led by Jazib Zaman. Page maintained by Jazib Zaman.

Reader Interactions

Share Your Thoughts Cancel reply

Before submitting your comment, we kindly ask that you read our comment policy. Your email address will remain confidential and will not be published or shared anywhere. If you subscribe, you will receive notifications regarding new comments.

Primary Sidebar

Education WordPress Theme

Free Education WordPress Themes For LMS & Educational Institutes

Rocket Managed WordPress Hosting

Rocket Managed WordPress Hosting Review

Recent Topics

  • Top Premium WordPress Plugins & Themes
  • How to Improve WordPress Navigation Menu
  • Publishing Blog Posts via Email: WordPress and Blogger
  • Ultimate Guide to Managing WordPress Multi Sites
  • 27 Top SEO Companies in the World

Footer

Top

  • Services
  • Our Themes
  • Facebook
  • Twitter
  • Linkedin

Reviews

  • Beaver Builder Review
  • Beaver Themer Review
  • WP User Frontend Pro
  • Ninja Forms Review
  • MemberPress Review

More Reviews »

Resources

  • Best WordPress Plugins
  • WordPress Permalinks Structure
  • Email Management System
  • Envato Free Files
  • Advertise
  • Write for us
  • Disclosure
  • Terms
  • Privacy
  • Contact

Copyright © 2023 · All Rights Reserved · WPArena is a Project of TechAbout LLC.
We are not affiliated with Automattic or WordPress.

  • Advertise
  • Write for us
  • Disclosure
  • Terms
  • Privacy
  • Contact
Share this ArticleLike this article? Email it to a friend!

Email sent!