A proper MongoDB Ubuntu Install helps developers and system administrators build a fast, scalable, and flexible NoSQL database environment on Linux servers. Unlike traditional relational databases, MongoDB stores information in JSON-like documents. As a result, developers can manage dynamic data structures more efficiently.
Moreover, MongoDB powers many modern web applications because it delivers strong performance, flexible schemas, and easy scalability. Ubuntu 22.04 also provides a stable and secure platform for hosting database workloads in both development and production environments.
MongoDB stands out because it handles large volumes of unstructured data with ease. In addition, it offers advanced indexing, replication, and high availability features that support enterprise applications.
Many developers choose MongoDB because it allows faster development cycles and easier scaling. Furthermore, Ubuntu 22.04 includes long-term support, making it a reliable operating system for database deployments.
Some major MongoDB features include:
Because of these advantages, MongoDB remains one of the most popular NoSQL databases available today.
Although Ubuntu includes MongoDB-related packages, they are often outdated. Therefore, most administrators prefer the official MongoDB repository for better security updates and newer releases.
First, update your package index and install the required dependencies:
sudo apt update sudo apt install gnupg wget apt-transport-https ca-certificates software-properties-common
Next, import the MongoDB GPG signing key:
wget -qO- https://pgp.mongodb.com/server-7.0.asc | \ gpg --dearmor | \ sudo tee /usr/share/keyrings/mongodb-server-7.0.gpg >/dev/null
After that, add the official MongoDB repository:
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] \ https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | \ sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
Now refresh the package list again and install MongoDB:
sudo apt update sudo apt install mongodb-org
Then start the MongoDB service and enable automatic startup during boot:
sudo systemctl enable --now mongod
Finally, verify the installation:
mongosh --eval 'db.runCommand({ connectionStatus: 1 })'
If the command returns "ok" : 1, MongoDB is running correctly.
Security should always remain a priority when deploying a database server. By default, local users may access MongoDB without authentication. Therefore, administrators should enable authorization immediately after installation.
Open the MongoDB configuration file:
sudo nano /etc/mongod.conf
Then locate the security section and enable authentication:
security: authorization: enabled
After saving the file, restart MongoDB to apply the changes:
sudo systemctl restart mongod
This configuration activates Role-Based Access Control (RBAC). Consequently, only authorized users can access or manage database resources.
After enabling authentication, create a dedicated administrator account for database management.
First, open the MongoDB shell:
mongosh
Next, switch to the admin database:
use admin
Then create the administrator account:
db.createUser({
user: "mongoAdmin",
pwd: passwordPrompt(),
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" }
]
})
Once MongoDB creates the account successfully, exit the shell.
Using a separate administrator account improves security significantly. Additionally, it helps organizations manage permissions more effectively.
A successful MongoDB Ubuntu Install on Ubuntu 22.04 gives developers a reliable and scalable NoSQL database platform. More importantly, using the official MongoDB repository ensures access to newer updates and security improvements.
After installation, you should enable authentication, configure RBAC, and create dedicated administrator accounts. By following these steps, you can build a more secure and production-ready MongoDB environment on Ubuntu servers.
Introduction Bash scripting is a powerful way to automate Linux tasks, but writing a script…
Introduction A self-signed SSL certificate is a certificate that is created and signed by the…
Introduction Debugging is an important part of Bash scripting. When a script does not work…
Introduction Cron jobs are used in Linux to run commands or Bash scripts automatically at…
Introduction Pipes are an important feature in Linux and Bash scripting. A pipe allows you…
Introduction The grep, awk, and sed commands are powerful text-processing tools in Linux. They are…