- Install MongoDB Community Edition on UbuntuВ¶
- OverviewВ¶
- MongoDB VersionВ¶
- ConsiderationsВ¶
- Platform SupportВ¶
- Production NotesВ¶
- Official MongoDB PackagesВ¶
- Install MongoDB Community EditionВ¶
- Import the public key used by the package management system.В¶
- Create a list file for MongoDB.В¶
- Reload local package database.В¶
- Install the MongoDB packages.В¶
- Run MongoDB Community EditionВ¶
- ProcedureВ¶
- Uninstall MongoDB Community EditionВ¶
- Stop MongoDB.В¶
- Install MongoDB Community Edition on Amazon LinuxВ¶
- OverviewВ¶
- Verify Linux DistributionВ¶
- MongoDB VersionВ¶
- ConsiderationsВ¶
- Platform SupportВ¶
- Production NotesВ¶
- Install MongoDB Community EditionВ¶
- Run MongoDB Community EditionВ¶
- ProcedureВ¶
- Uninstall MongoDB Community EditionВ¶
- Stop MongoDB.В¶
- How to Install MongoDB on Ubuntu
- Installing MongoDB on Ubuntu based Distributions
- Method 1. Install MongoDB from Ubuntu Repository
- Installing MongoDB
- Running MongoDB
- Uninstall MongoDB
- Method 2. Install MongoDB Community Edition on Ubuntu
- Installing MongoDB
- Configuring MongoDB
- Running MongoDB
- Uninstall MongoDB
Install MongoDB Community Edition on UbuntuВ¶
MongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started.
OverviewВ¶
Use this tutorial to install MongoDB 5.0 Community Edition on LTS (long-term support) releases of Ubuntu Linux using the apt package manager.
MongoDB VersionВ¶
This tutorial installs MongoDB 5.0 Community Edition. To install a different version of MongoDB Community , use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
ConsiderationsВ¶
Platform SupportВ¶
- MongoDB 5.0 Community Edition removes support for Ubuntu 16.04 on x86_64
- MongoDB 5.0 Community Edition removes support for Ubuntu 18.04 on s390x
MongoDB 5.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 5.0 Community Edition on Ubuntu also supports the ARM64 architecture on select platforms.
See Supported Platforms for more information.
To run MongoDB in Windows Subsystem for Linux (WSL), refer to the WSL documentation.
Production NotesВ¶
Before deploying MongoDB in a production environment, consider the Production Notes document which offers performance considerations and configuration recommendations for production MongoDB deployments.
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.
The mongodb package provided by Ubuntu is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you have already installed the mongodb package on your Ubuntu system, you must first uninstall the mongodb package before proceeding with these instructions.
See MongoDB Community Edition Packages for the complete list of official packages.
Install MongoDB Community EditionВ¶
Follow these steps to install MongoDB Community Edition using the apt package manager.
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-5.0.asc:
The operation should respond with an OK .
However, if you receive an error indicating that gnupg is not installed, you can:
Install gnupg and its required libraries using the following command:
Once installed, retry importing the key:
Create a list file for MongoDB.В¶
Create the list file /etc/apt/sources.list.d/mongodb-org-5.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 .
Reload local package database.В¶
Issue the following command to reload the local package database:
Install the MongoDB packages.В¶
You can install either the latest stable version of MongoDB or a specific version of MongoDB.
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:
For help with troubleshooting errors encountered while installing MongoDB on Ubuntu, see our troubleshooting guide.
Run MongoDB Community EditionВ¶
If you installed via the package manager, the data directory /var/lib/mongodb and the log directory /var/log/mongodb are created during the installation.
By default, MongoDB runs using the mongodb user account. If you change the user that runs the MongoDB process, you must also modify the permission to the data and log directories to give this user access to these directories.
Configuration File The official MongoDB package includes a configuration file ( /etc/mongod.conf ). These settings (such as the data directory and log directory specifications) take effect upon startup. That is, if you change the configuration file while the MongoDB instance is running, you must restart the instance for the changes to take effect.
ProcedureВ¶
Follow these steps to run MongoDB Community Edition on your system. These instructions assume that you are using the official mongodb-org package — not the unofficial mongodb package provided by Ubuntu — and are using the default settings.
Init System
To run and manage your mongod process, you will be using your operating system’s built-in init system. Recent versions of Linux tend to use systemd (which uses the systemctl command), while older versions of Linux tend to use System V init (which uses the service command).
If you are unsure which init system your platform uses, run the following command:
Then select the appropriate tab below based on the result:
- systemd — select the systemd (systemctl) tab below.
- init — select the System V Init (service) tab below.
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.
This process will completely remove MongoDB, its configuration, and all databases. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding.
Stop MongoDB.В¶
Stop the mongod process by issuing the following command:
Источник
Install MongoDB Community Edition on Amazon LinuxВ¶
MongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started.
OverviewВ¶
Use this tutorial to install MongoDB 5.0 Community Edition on Amazon Linux using the yum package manager.
Verify Linux DistributionВ¶
You can verify which Linux distribution you are running by running the following command on the command-line:
The result should be Amazon Linux or Amazon Linux AMI. If using a different Linux distribution, please see the install instructions for your platform.
MongoDB VersionВ¶
This tutorial installs MongoDB 5.0 Community Edition. To install a different version of MongoDB Community , use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
ConsiderationsВ¶
Platform SupportВ¶
MongoDB 5.0 Community Edition supports the following 64-bit Amazon Linux release on x86_64 architecture:
MongoDB only supports the 64-bit versions of this platform.
MongoDB 5.0 Community Edition on Amazon Linux also supports the ARM64 architecture on select platforms.
See Supported Platforms for more information.
Production NotesВ¶
Before deploying MongoDB in a production environment, consider the Production Notes document which offers performance considerations and configuration recommendations for production MongoDB deployments.
Install MongoDB Community EditionВ¶
Follow these steps to install MongoDB Community Edition using the yum package manager. Select the tab for your version of Amazon Linux:
Run MongoDB Community EditionВ¶
ProcedureВ¶
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
Init System
To run and manage your mongod process, you will be using your operating system’s built-in init system. Recent versions of Linux tend to use systemd (which uses the systemctl command), while older versions of Linux tend to use System V init (which uses the service command).
If you are unsure which init system your platform uses, run the following command:
Then select the appropriate tab below based on the result:
- systemd — select the systemd (systemctl) tab below.
- init — select the System V Init (service) tab below.
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.
This process will completely remove MongoDB, its configuration, and all databases. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding.
Stop MongoDB.В¶
Stop the mongod process by issuing the following command:
Источник
How to Install MongoDB on Ubuntu
Last updated March 4, 2019 By Sergiu 10 Comments
This tutorial presents two ways to install MongoDB on Ubuntu and Ubuntu-based Linux distributions.
MongoDB is an increasingly popular free and open-source NoSQL database that stores data in collections of JSON-like, flexible documents, in contrast to the usual table approach you’ll find in SQL databases.
You are most likely to find MongoDB used in modern web applications. Its document model makes it very intuitive to access and handle with various programming languages.
In this article, I’ll cover two ways you can install MongoDB on your Ubuntu system.
Installing MongoDB on Ubuntu based Distributions
- Install MongoDB using Ubuntu’s repository. Easy but not the latest version of MongoDB
- Install MongoDB using its official repository. Slightly complicated but you get the latest version of MongoDB.
The first installation method is easier, but I recommend the second method if you plan on using the latest release with official support.
Some people might prefer using snap packages. There are snaps available in the Ubuntu Software Center, but I wouldn’t recommend using them; they’re outdated at the moment and I won’t be covering that.
Method 1. Install MongoDB from Ubuntu Repository
This is the easy way to install MongoDB on your system, you only need to type in a simple command.
Installing MongoDB
First, make sure your packages are up-to-date. Open up a terminal and type:
Go ahead and install MongoDB with:
That’s it! MongoDB is now installed on your machine.
The MongoDB service should automatically be started on install, but to check the status type
You can see that the service is active.
Running MongoDB
MongoDB is currently a systemd service, so we’ll use systemctl to check and modify it’s state, using the following commands:
You can also change if MongoDB automatically starts when the system starts up (default: enabled):
To start working with (creating and editing) databases, type:
This will start up the mongo shell. Please check out the manual for detailed information on the available queries and options.
Note: Depending on how you plan to use MongoDB, you might need to adjust your Firewall. That’s unfortunately more involved than what I can cover here and depends on your configuration.
Uninstall MongoDB
If you installed MongoDB from the Ubuntu Repository and want to uninstall it (maybe to install using the officially supported way), type:
This should completely get rid of your MongoDB install. Make sure to backup any collections or documents you might want to keep since they will be wiped out!
Method 2. Install MongoDB Community Edition on Ubuntu
This is the way the recommended way to install MongoDB, using the package manager. You’ll have to type a few more commands and it might be intimidating if you are newer to the Linux world.
But there’s nothing to be afraid of! We’ll go through the installation process step by step.
Installing MongoDB
The package maintained by MongoDB Inc. is called mongodb-org, not mongodb (this is the name of the package in the Ubuntu Repository). Make sure mongodb is not installed on your system before applying this steps. The packages will conflict. Let’s get to it!
First, we’ll have to import the public key:
Now, you need to add a new repository in your sources list so that you can install MongoDB Community Edition and also get automatic updates:
To be able to install mongodb -org, we’ll have to update our package database so that your system is aware of the new packages available:
Now you can ether install the latest stable version of MongoDB:
or a specific version (change the version number after equal sign)
If you choose to install a specific version, make sure you change the version number everywhere. If you only change it in the mongodb-org=4.0.6 part, the latest version will be installed.
By default, when updating using the package manager (apt-get), MongoDB will be updated to the newest updated version. To stop that from happening (and freezing to the installed version), use:
You have now successfully installed MongoDB!
Configuring MongoDB
By default, the package manager will create /var/lib/ mongodb and /var/log/ mongodb and MongoDB will run using the mongodb user account.
I won’t go into changing these default settings since that is beyond the scope of this guide. You can check out the manual for detailed information.
The settings in /etc/mongod.conf are applied when starting/restarting the mongodb service instance.
Running MongoDB
To start the mongodb daemonmongod, type:
Now you should verify that the mongod process started successfully. This information is stored (by default) at /var/log/mongodb/mongod.log. Let’s check the contents of that file:
As long as you get this: [initandlisten] waiting for connections on port 27017 somewhere in there, the process is running properly.
Note: 27017 is the default port of mongod.
To stop/restart mongod enter:
Now, you can use MongoDB by opening the mongo shell:
Uninstall MongoDB
Run the following commands
To remove the databases and log files (make sure to backup what you want to keep!):
Wrapping Up
MongoDB is a great NoSQL database, easy to integrate in to modern projects. I hope this tutorial helped you to set it up on your Ubuntu machine! Let us know how you plan on using MongoDB in the comments below.
Like what you read? Please share it with others.
Источник