Go to the documentation pages and select your distro, architecture and version:
https://docs.mongodb.com/manual/administration/install-on-linux/
For Ubuntu:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
- Import the MongoDB software signing key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
- Create an apt sources list file for Ubuntu 18.04 LTS (Bionic):
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
- Update package cache:
sudo apt-get update
- Install the MongoDB packages:
sudo apt-get install -y mongodb-org
This will install not only the server, but also clients, tools and drivers.
Server components will be located:
Confguration: /etc/mongod.conf
Data files: /var/lib/mongodb
Logs: /var/log/mongodb.log
Start/stop/get status of server:
$ sudo systemctl start mongod
$ sudo systemctl status mongod
$ sudo systemctl stop mongod
Set to start with system:
$ sudo systemctl enable mongod