How to Install MongoDB 6.0 on Ubuntu 20 | MongoDB-org
Overview
Use this tutorial to install MongoDB 6.0 Community Edition on LTS (long-term support) releases of Ubuntu Linux using the apt package manager.
Platform Support
MongoDB 6.0 Community Edition supports the following 64-bit Ubuntu LTS (long-term support) releases on x86_64 architecture:
20.04 LTS ("Focal")
18.04 LTS ("Bionic")
16.04 LTS ("Xenial")
MongoDB only supports the 64-bit versions of these platforms.
MongoDB 6.0 Community Edition on Ubuntu also supports the ARM64 architecture on select platforms.
Official MongoDB Packages:
To install MongoDB Community on your Ubuntu system, these instructions will use the official mongodb-org package, which is maintained and supported by MongoDB Inc. The official mongodb-org package always contains the latest version of MongoDB, and is available from its own dedicated repo.
Install MongoDB Community Edition
Follow these steps to install MongoDB Community Edition using the apt package manager.
1. Import the public key used by the package management system.
From a terminal, issue the following command to import the MongoDB public GPG Key from https://www.mongodb.org/static/pgp/server-6.0.asc :
# wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
The operation should respond with an OK.
However, if you receive an error indicating that gnupg is not installed, you can:
1) Install gnupg and its required libraries using the following command:
# sudo apt-get install gnupg
2) Once installed, retry importing the key:
# wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
2. Create a list file for MongoDB.
Create the list file /etc/apt/sources.list.d/mongodb-org-6.0.list for your version of Ubuntu.
Click on the appropriate tab for your version of Ubuntu. If you are unsure of what Ubuntu version the host is running, open a terminal or shell on the host and execute lsb_release -dc.
Ubuntu 20.04 (Focal).
Create the /etc/apt/sources.list.d/mongodb-org-6.0.list file for Ubuntu 20.04 (Focal):
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
Ubuntu 18.04 (Bionic).
Create the /etc/apt/sources.list.d/mongodb-org-6.0.list file for Ubuntu 18.04 (Bionic):
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
Ubuntu 16.04 (Xenial).
Create the /etc/apt/sources.list.d/mongodb-org-6.0.list file for Ubuntu 16.04 (Xenial):
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
3. Reload local package database.
Issue the following command to reload the local package database:
# sudo apt-get update
4. Install the MongoDB packages.
You can install either the latest stable version of MongoDB or a specific version of MongoDB.
To install the latest stable version, issue the following
# sudo apt-get install -y mongodb-org
Optional. Although you can specify any available version of MongoDB, apt-get will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, you can pin the package at the currently installed version:
# echo "mongodb-org hold" | sudo dpkg --set-selections
# echo "mongodb-org-database hold" | sudo dpkg --set-selections
# echo "mongodb-org-server hold" | sudo dpkg --set-selections
# echo "mongodb-mongosh hold" | sudo dpkg --set-selections
# echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
# echo "mongodb-org-tools hold" | sudo dpkg --set-selections
1. Start MongoDB
You can start the mongod process by issuing the following command:
# sudo systemctl start mongod
If you receive an error similar to the following when starting mongod:
Failed to start mongod.service: Unit mongod.service not found.
Run the following command first:
# sudo systemctl daemon-reload
Then run the start command above again.
2. Verify that MongoDB has started successfully.
# sudo systemctl status mongod
You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:
# sudo systemctl enable mongod
5. Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
# mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port
Uninstall MongoDB Community Edition:
To completely remove MongoDB from a system, you must remove the MongoDB applications themselves, the configuration files, and any directories containing data and logs. The following section guides you through the necessary steps.
1. Stop MongoDB.
Stop the mongod process by issuing the following command:
# sudo service mongod stop
2. Remove Packages.
Remove any MongoDB packages that you had previously installed.
# sudo apt-get purge mongodb-org*
3. Remove Data Directories.
Remove MongoDB databases and log files.
# sudo rm -r /var/log/mongodb
# sudo rm -r /var/lib/mongodb
Additional Information
Localhost Binding by Default:
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
Comments
Post a Comment