To install MongoDB on a Linux server, follow these steps:
Import the MongoDB public GPG Key:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
Create a list file for MongoDB:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Reload the local package database:
sudo apt-get update
Install the MongoDB packages:
sudo apt-get install -y mongodb-org
Start MongoDB:
sudo systemctl start mongod
Verify that MongoDB has started successfully:
sudo systemctl status mongod
Enable MongoDB to start on boot:
sudo systemctl enable mongod
MongoDB should now be installed and running on your Linux server. You can connect to the MongoDB shell using the mongo
command.