Monday, June 22, 2020

How to Install MongoDB on Linux Ubuntu 18.04

1- Import the MongoDB public GPG Key:
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
view raw sh hosted with ❤ by GitHub
2- Create the /etc/apt/sources.list.d/mongodb-org-4.2.list file for Ubuntu 18.04 (Bionic):
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
view raw sh hosted with ❤ by GitHub
3- Reload the local package database:
sudo apt-get update
view raw sh hosted with ❤ by GitHub
4- Install MongoDB:
sudo apt-get install -y mongodb-org=4.2.8 mongodb-org-server=4.2.8 mongodb-org-shell=4.2.8 mongodb-org-mongos=4.2.8 mongodb-org-tools=4.2.8
view raw sh hosted with ❤ by GitHub
5- Start MongoDB service:
sudo systemctl start mongod
view raw sh hosted with ❤ by GitHub
6- Start a Mongo shell:
mongo
view raw sh hosted with ❤ by GitHub
8- Create users database:
use admin
view raw sh hosted with ❤ by GitHub
9- Create an adminstrator user:
db.createUser({
user: 'admin',
pwd: 'password',
roles: [{ role: 'root', db:'admin'}]
})
view raw sh hosted with ❤ by GitHub
10- Exit the Mongo shell:
exit
view raw sh hosted with ❤ by GitHub
11- Open the MongoDB configuration file sudo vim /etc/mongod.conf and edit the following parameters:
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
security:
authorization: enabled
view raw conf hosted with ❤ by GitHub
12- Restart MongoDB process:
sudo systemctl restart mongod
view raw sh hosted with ❤ by GitHub

No comments:

Post a Comment