How to Install MongoDB on Ubuntu 14.04 LTS
MongoDB is a NoSQL database intended for storing large amounts of data in document-oriented storage with dynamic schemas. NoSQL refers to a database with a data model other than the tabular format used in relational databases such as MySQL, PostgreSQL, and Microsoft SQL. MongoDB features include: full index support, replication, high availability, and auto-sharding.
- These instructions are intended for installing MongoDB on a single Ubuntu 14.04 LTS node.
- I’ll be working from a Liquid Web Core Managed Ubuntu 14.04 LTS server, and I’ll be logged in as a non-root user, but with sudo access. For information on giving a user sudo access visit our page on How to Add a User and Grant Root Privileges on Ubuntu 14.04.
First we’ll import the MongoDB public key used by the package management system:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Then we’ll create a list file for MongoDB:
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
Now reload the package database:
sudo apt-get update
At this point, installing MongoDB is as simple as running just one command:
sudo apt-get install -y mongodb-org
If you’d like MongoDB to auto-update with apt-get than you’re done with the installation. But, it’s possible to ‘pin’ the version of MongoDB you just installed to prevent apt-get from auto-updating.
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
Start-Up MongoDB
sudo service mongod start
Check MongoDB Service Status
sudo service mongod status
Summary List of Status Statistics (Continuous)
mongostat
Summary List of Status Statistics (5 Rows, Summarized Every 2 Seconds)
mongostat --rowcount 5 2
Enter the MongoDB Command Line
mongo
By default, running this command will look for a MongoDB server listening on port 27017 on the localhost interface.
If you’d like to connect to a MongoDB server running on a different port, then use the –port option. For example, if you wanted to connect to a local MongoDB server listening on port 22222, then you’d issue the following command:
mongo --port 22222
Shutdown MongoDB
sudo service mongod stop
Restart MongoDB
sudo service mongod restart
Related Articles:
About the Author: J. Mays
As a previous contributor, JMays shares his insight with our Knowledge Base center. In our Knowledge Base, you'll be able to find how-to articles on Ubuntu, CentOS, Fedora and much more!
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Install ClamAV
Read ArticleHow to Use Disk Quotas in Dedicated Linux Servers with Plesk
Read ArticleGuide on Connecting to Remote Servers Using SSH in Linux, Windows, or macOS Systems
Read ArticleNew User Tutorial: What is DNS?
Read ArticleDifference Between AlmaLinux and Rocky Linux
Read Article