To install MongoDB on Ubuntu 22, you can follow these steps:
Update the System
Open a terminal and run the following command to update the system packages:
sudo apt update
Import the MongoDB GPG Key
Import the MongoDB GPG key to verify the authenticity of the MongoDB packages. Run the following command:
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Add MongoDB Repository
Add the MongoDB repository to your system. Run the following command:
echo "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
Update the System
Again, update the system packages to include the MongoDB repository:
sudo apt update
Install MongoDB
Now, you can install MongoDB by running the following command:
sudo apt install mongodb-org
This command installs the MongoDB packages, including the MongoDB server (`mongod`), MongoDB shell (`mongo`), and other MongoDB tools.
Start MongoDB Service
After the installation is complete, start the MongoDB service by running:
sudo systemctl start mongod
You can also enable MongoDB to start automatically on system boot with the following command:
sudo systemctl enable mongod
Verify MongoDB Installation
To verify that MongoDB is installed and running, use the following command:
mongo --version
You should see the version information displayed if MongoDB is installed correctly.
That's it! MongoDB is now installed on your Ubuntu 22 system. You can start using MongoDB by running the `mongo` command in the terminal or by connecting to MongoDB from your PHP application.
More Articles on this topic:
- What is MongoDB and how to use it from PHP
- What is the aggregation framework in mongodb and examples in PHP