SiteCozy

  • My account

How to install MongoDB community on ubuntu 18

2018-09-21

Import the keys and add the mongoDB lists to the source lists so that everytime you will do an apt-get update it will check if new versions of any Mongodb modules exist.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

The command below will load the source lists in which there are the mongoDB packages.

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

In case you don’t want a mongodb module to be automatically updated when you type a “apt-get update”, you can disable the update of a module by typing one of the directives below.

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

Now it is time to add the mongod service to the system. 

sudo systemctl enable mongod
sudo systemctl start mongod

Let’s check if it is working. Mongodb listens on the 27017 port. Type the command below and you should see in the list something like LISTEN 127.0.0.1:27017

ss -ltpn

When you install MongoDB, there is no admin user and no authentication. You must set it up manually. Open the terminal and start a mongo session:

mongo
use admin
db.createUser({ user: "mongoadmin" , pwd: "mongoadmin", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})

Now go to the service file of the mongo server module and add the –auth parameter to ExecStart=/usr/bin/mongod –auth –config /etc/mongod.conf

sudo nano /lib/systemd/system/mongod.service

Then, type sudo systemctl daemon-reload && sudo systemctl restart mongod

Now to open a mongo session and login as admin with a password

mongo admin -u mongoadmin -p 'mongoadmin'


Related Posts:

  • How to install nodeBB on ubuntu
  • How to install nodeBB on centos 7
  • How to fix the cyclic dependancy error in nodeJS/mongodb
Download our Broken link checker freeware here Buy a license key for the Sitecozy broken link checker

Customer Login

Lost password?

Categories

  • Webmaster advice
  • SEO advice
  • Web hosting
  • SiteCozy link checker KB
  • WordPress theme & plugin reviews
  • All articles
Disclosure: We are a professional review site that receives compensation from the companies whose products we review. We test each product thoroughly and give high marks to only the very best. We are independently owned and the opinions expressed here are our own.

Copyright Sitecozy 2018