- Introduction
- Why can’t we install MongoDB on Raspberry Pi?
- Prerequisites
- Parts/Components Required
- Ubuntu Installation Steps
- Make MongoDB available to the network
- Uninstall MongoDB on Ubuntu?
- Install old MongoDB on Raspberry Pi OS (Not Working!)
- How to install MongoDB on Raspberry Pi OS (formerly Raspbian)
- What if I want to use the latest MongoDB?
- Wrap Up
Introduction
If you are looking for ways, how to install the latest MongoDB (6.0 as of this time) on your Raspberry Pi then it is not possible! But if it is okay for you to work with the lower version of this awesome NoSQL database then continue reading on.
Why can’t we install MongoDB on Raspberry Pi?
I wrote this post because if you try searching for ways how to install MongoDB on Raspberry Pi then you might be thinking that it is possible and the google top searches will tell you that it should work. However, you would run into the following issue “mongod.service: Main process exited, code=killed, status=4/ILL” and the complete error shown below.
pi@raspberrypi4:~ $ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: signal) since Sat 2023-03-04 09:50:25 PST; 1h 2min ago
Docs: https://docs.mongodb.org/manual
Process: 539 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=killed, signal=ILL)
Main PID: 539 (code=killed, signal=ILL)
CPU: 84ms
Mar 04 09:50:24 raspberrypi4 systemd[1]: Started MongoDB Database Server.
Mar 04 09:50:25 raspberrypi4 systemd[1]: mongod.service: Main process exited, code=killed, status=4/ILL
Mar 04 09:50:25 raspberrypi4 systemd[1]: mongod.service: Failed with result 'signal'.
The reason is that Raspberry Pi 4 unfortunately does not meet the CPU microarchitecture requirements for MongoDB 5.0 binary packages which you can find here. This is also documented in the MongoDB forum here.
So only MongoDB 4.4 packages are the last supported version of MongoDB that you can install on your Raspberry Pi. I spent some time figuring out why my MongoDB service on my Raspberry Pi did not start so that is why I documented my misadventures in this post. 🙂
You could try building from source and exploring if it would work but I do not want to go there.
Prerequisites
You need to have your Raspberry Pi running the latest Ubuntu Linux distribution. I am using a Windows/PC as my workstation to connect to my Raspberry Pi.
Related Content:
Install Headless Ubuntu Server on Raspberry Pi – No Monitor
Also, you need to verify the version of your Ubuntu as it should not be greater than the 20.04 version or the ‘focal’ codename. To know your Ubuntu version then please type the below command.
pi@raspberrypi:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal
Parts/Components Required
The following is the component required to follow along with this post but you can use other Raspberry Pi device variants that can support the Ubuntu Linux distribution.
- Raspberry Pi 4B – Amazon | AliExpress
Disclosure: These are affiliate links and I will earn small commissions to support my site when you buy through these links.
Ubuntu Installation Steps
The following are the steps on how to install the MongoDB package to your Raspberry Pi running the Ubuntu Linux distribution.
Connect to your Raspberry Pi
Connect to your Raspberry Pi using SSH or Putty.
Update your Raspberry Pi
It is always a good idea to update your Raspberry Pi device to get the latest firmware and libraries as there could be some performance improvements or security patches. Execute the below code to update your device.
sudo apt update && sudo apt upgrade -y
This might take some time so make sure to let your device finish this operation to avoid any data corruption.
Add GPG Key for MongoDB
Next, we add the GPG key for MongoDB to our Raspberry Pi device by executing the below code.
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
You should be seeing the OK message.
Add the MongoDB source location
We then need to add the MongoDB repository to the repository list of our device by executing the below code. This will tell the package manager where to download the binaries for our MongoDB installer.
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
After installing the steps above then you should be seeing the following file in your Raspberry Pi repository directory.
pi@raspberrypi:~$ ls -l /etc/apt/sources.list.d/
total 4
-rw-r--r-- 1 root root 94 Mar 5 12:56 mongodb-org-4.4.list
Update the source list
Since we have added a new repository to our repository list then we need to refresh our device by executing the below code.
sudo apt-get update
After executing the step above then you should be seeing the following message below which means that it was able to retrieve the package details from our MongoDB repository and our source list is now updated.
pi@raspberrypi:~$ sudo apt-get update
Ign:1 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 InRelease
Get:2 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 Release [3094 B]
Hit:3 http://ports.ubuntu.com/ubuntu-ports focal InRelease
Get:4 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 Release.gpg [801 B]
Get:5 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease [114 kB]
Get:6 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4/multiverse arm64 Packages [30.1 kB]
Hit:7 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease
Get:8 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4/multiverse amd64 Packages [38.1 kB]
Hit:9 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease
Fetched 186 kB in 3s (53.5 kB/s)
Reading package lists... Done
Install MongoDB
If everything is ok from the previous steps then we can proceed to the MongoDB installation by executing the below code.
sudo apt-get install -y mongodb-org=4.4.18 mongodb-org-server=4.4.18 mongodb-org-shell=4.4.18 mongodb-org-mongos=4.4.18 mongodb-org-tools=4.4.18
If you noticed from the command above that I am installing the 4.4.18 version and that is because if you execute the below command then it will install the 4.4.19 version on MongoDB. Unfortunately, it does not work on my setup so I downgraded to the next lower version.
sudo apt-get install -y mongodb-org
You should be seeing the following message displayed on your terminal.
pi@raspberrypi:~$ sudo apt-get install -y mongodb-org=4.4.18 mongodb-org-server=4.4.18 mongodb-org-shell=4.4.18 mongodb-org-mongos=4.4.18 mongodb-org-tools=4.4.18
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
mongodb-mongosh
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
mongodb-org-database-tools-extra
The following NEW packages will be installed:
mongodb-org mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 46.3 MB/46.3 MB of archives.
After this operation, 195 MB of additional disk space will be used.
Get:1 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4/multiverse arm64 mongodb-org-shell arm64 4.4.18 [12.4 MB]
Get:2 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4/multiverse arm64 mongodb-org-server arm64 4.4.18 [18.9 MB]
Get:3 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4/multiverse arm64 mongodb-org-mongos arm64 4.4.18 [15.0 MB]
Get:4 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4/multiverse arm64 mongodb-org-tools arm64 4.4.18 [2892 B]
Get:5 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4/multiverse arm64 mongodb-org arm64 4.4.18 [3520 B]
Fetched 46.3 MB in 9s (5171 kB/s)
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 101165 files and directories currently installed.)
Preparing to unpack .../0-mongodb-org-shell_4.4.18_arm64.deb ...
Unpacking mongodb-org-shell (4.4.18) ...
Selecting previously unselected package mongodb-org-server.
Preparing to unpack .../1-mongodb-org-server_4.4.18_arm64.deb ...
Unpacking mongodb-org-server (4.4.18) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../2-mongodb-org-mongos_4.4.18_arm64.deb ...
Unpacking mongodb-org-mongos (4.4.18) ...
Selecting previously unselected package mongodb-org-database-tools-extra.
Preparing to unpack .../3-mongodb-org-database-tools-extra_4.4.19_arm64.deb ...
Unpacking mongodb-org-database-tools-extra (4.4.19) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../4-mongodb-org-tools_4.4.18_arm64.deb ...
Unpacking mongodb-org-tools (4.4.18) ...
Selecting previously unselected package mongodb-org.
Preparing to unpack .../5-mongodb-org_4.4.18_arm64.deb ...
Unpacking mongodb-org (4.4.18) ...
Setting up mongodb-org-server (4.4.18) ...
Setting up mongodb-org-shell (4.4.18) ...
Setting up mongodb-org-mongos (4.4.18) ...
Setting up mongodb-org-database-tools-extra (4.4.19) ...
Setting up mongodb-org-tools (4.4.18) ...
Setting up mongodb-org (4.4.18) ...
Processing triggers for man-db (2.9.1-1) ...
Run MongoDB
After the installation is successful then we can start the MongoDB service and configure it also to run during the startup of your Raspberry Pi. Execute the below command to start the service
# Start the MongoDB service
sudo systemctl start mongod
If everything is okay then you can check the status by executing the below code.
sudo systemctl status mongod
You should be seeing the following message
pi@raspberrypi:~$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2023-03-05 13:12:29 PST; 11s ago
Docs: https://docs.mongodb.org/manual
Main PID: 5589 (mongod)
CGroup: /system.slice/mongod.service
└─5589 /usr/bin/mongod --config /etc/mongod.conf
Mar 05 13:12:29 raspberrypi systemd[1]: Started MongoDB Database Server.
But if an error occurred or the service is not starting then execute the below code.
sudo systemctl daemon-reload
How to check the MongoDB version in Ubuntu? Execute the below code.
pi@raspberrypi:~$ mongod --version
db version v4.4.18
Build Info: {
"version": "4.4.18",
"gitVersion": "8ed32b5c2c68ebe7f8ae2ebe8d23f36037a17dea",
"openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu2004",
"distarch": "aarch64",
"target_arch": "aarch64"
}
}
Configure MongoDB to start at reboot
If you want your MongoDB to start during reboot then configure it by executing the below code.
sudo systemctl enable mongod
Validate your MongoDB Installation
You can now begin interacting with your MongoDB database by running the mongo client like the below code.
pi@raspberrypi:~$ mongo
MongoDB shell version v4.4.18
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c01d5776-845d-4635-86ae-056de85fcb9c") }
MongoDB server version: 4.4.18
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
---
The server generated these startup warnings when booting:
2023-03-05T13:12:30.327+08:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2023-03-05T13:12:32.551+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
>
Make MongoDB available to the network
If you are planning to access your MongoDB instance outside of your Raspberry Pi device then you need to edit the /etc/mongod.conf file and change the bindIp tp “0.0.0.0”
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
Reload your MongoDB instance by executing the below code.
sudo systemctl restart mongod
Uninstall MongoDB on Ubuntu?
Stop the MongoDB service
We need to stop the MongoDB service if it is running prior to the uninstallation by executing the below commands.
sudo service mongod stop
Uninstall the MongoDB package
To remove the MongoDB package then execute the below code.
sudo apt-get purge mongodb-org*
You should see the following messages displayed on your terminal.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'mongodb-org-database-tools-extra' for glob 'mongodb-org*'
Note, selecting 'mongodb-org-shell' for glob 'mongodb-org*'
Note, selecting 'mongodb-org-server' for glob 'mongodb-org*'
Note, selecting 'mongodb-org' for glob 'mongodb-org*'
Note, selecting 'mongodb-org-tools' for glob 'mongodb-org*'
Note, selecting 'mongodb-org-mongos' for glob 'mongodb-org*'
The following packages were automatically installed and are no longer required:
mongodb-database-tools raspinfo
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
mongodb-org* mongodb-org-database-tools-extra* mongodb-org-mongos* mongodb-org-server* mongodb-org-shell* mongodb-org-tools*
0 upgraded, 0 newly installed, 6 to remove and 6 not upgraded.
After this operation, 194 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 100063 files and directories currently installed.)
Removing mongodb-org (4.4.19) ...
Removing mongodb-org-tools (4.4.19) ...
Removing mongodb-org-database-tools-extra (4.4.19) ...
Removing mongodb-org-mongos (4.4.19) ...
Removing mongodb-org-server (4.4.19) ...
Removing mongodb-org-shell (4.4.19) ...
Processing triggers for man-db (2.9.4-2) ...
(Reading database ... 100029 files and directories currently installed.)
Purging configuration files for mongodb-org-server (4.4.19) ...
Purging configuration files for mongodb-org (4.4.19) ...
Cleanup MongoDB directory
Remove the directories that MongoDB is using as its data and log directory if ever.
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
Install old MongoDB on Raspberry Pi OS (Not Working!)
There are some sites that say that you can install older MongoDB by executing the below commands which will install an old version of MongoDB that is not managed by the MongoDB team.
sudo apt install mongodb
I tried it on my Raspberry Pi OS (formerly Raspbian) but I encountered the following issue which I think is a good thing because that package may not be properly maintained and may pose a security risk to your device.
pi@raspberrypi4:~ $ sudo apt install mongodb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package mongodb is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'mongodb' has no installation candidate
How to install MongoDB on Raspberry Pi OS (formerly Raspbian)
As I have mentioned, the Raspberry Pi microarchitecture device itself cannot support the MongoDB package since the 5.0 version. But you can install the 4.4 version which is still supported by MongoDB. If you are okay with this version then just follow the steps above on the Ubuntu installation as they are applicable to the current release of the Raspberry pi OS.
What if I want to use the latest MongoDB?
Well, you are out of luck as MongoDB 5.0+ or later is not supported anymore on your Raspberry Pi. If you want you can try the cloud version of MongoDB which is MongoDB Atlas and there is no installation needed.
Related Content:
MongoDB Atlas: An Overview and how to get started
Wrap Up
I hope this post helps answer your question on how to install MongoDB and Raspberry Pi. To emphasize, it is not feasible to install MongoDB version 5.0 and above to your Raspberry Pi as the device MicroArchitecture is not supported anymore but you can still use the 4.4 old version. If you still need the new features of MongoDB then I highly suggest using MongoDB Atlas.
I hope you learn something! Happy Exploring!
Leave a Reply