Install MongoDB
To install MongoDB,
SSH into your server as root
and run the following commands.
apt-get install gnupg curlcurl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
Determine which version of Ubuntu the server is running.
cat /etc/lsb-release
Referencing the output from above, run the command below that matches your version of Ubuntu.
# Ubuntu 24.04:echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
# Ubuntu 22.04:echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
# Ubuntu 20.04:echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
Next, install the MongoDB package and start the service.
apt-get updateapt-get install -y mongodb-orgsystemctl daemon-reloadsystemctl enable mongodsystemctl start mongod
MongoDB will listen on port 27017.