MongoDB 5.0 under Raspberry Pi OS (64-bit)

MongoDB 5.0.5 for Raspbian Pi OS (64-bit)

[UPDATED: 12 Jan 2022 with MongoDB 5.0.5 binaries] There is no official support from MongoDB for Debian ARM 64 or Raspbian64 Linux OS (now known as Raspberry Pi OS 64-bit).  You can, however, compile the MongoDB Community Edition from source.  I did just that 🙂  It did, however, take three days and a burnt Raspberry Pi 4 to accomplish 🙁  I’ll provide a link to instructions to create the executables for mongod, mongos and mongo — as well as provide a few tips to successfully compile.  Better and easier than that, I provide links to already compiled versions with instructions on how to install and use.

I recently decided to “check-in” on the status of Raspbian64, the 64 bit version of Raspberry Pi OS which is not yet released. I had been using Ubuntu Server 20.04 ARM 64-bit on a couple of Raspberry Pi 4s for various projects. One benefit of Ubuntu was official support for MongoDB. I was looking for a complete optimized Raspbian OS with GUI AND MongoDB. Searching around, I did not find what I wanted. I decided to try and create it.

You’ll need to find and install the latest Raspbian64 image. Use the “full” version as opposed to “lite” as you need all the tools, such as dev libraries, g++-8 and git that come with the full version. Not that you could not use “lite” and install everything needed 😉 This is the version I use with its GUI as it has great internet and development tools. I can also use via VNC in headless mode.

If you really want to compile MongoDB Community Edition 4.4.8 from source, you can find instructions in this thread in the MongoDB Community Forums. NOTE that you will need to add at least a 4GB swap file on your 4GB RAM R-Pi 4. You should change the git command that grabs version 4.2.8 so that you get the latest: 4.4.8 or 5.0.5.

git clone -b r4.4.8

OR, for version 5.0.5

git clone -b r5.0.5

Compiling is straightforward but I had a few issues along the way. I used a Raspberry Pi 4 in a Flirc case with a USB 3 attached SSD. I have had my Pi 4 overclocked to 2GHz with no issues or overheating for quite some time. I love the Flirc case as it looks good and the whole aluminum case is a big heatsink. The first couple of times I tried to compile MongoDB from source, the build would just die after an hour or so. By monitoring the Pi with another ssh login, it looked like it was running out of real and swap memory. I could also see the 4 cores were running at over 90% usage. I upped the swap file to 2GB and tried again. This time, the build lasted over 4 hours before hanging (died silently). I picked up the Pi 4 case and almost burned my hand (ouch!). Being foolish, I tried again — with, of course the same result — a hung Pi that now had the electronic overheat smell 🙁 I moved the SSD to my *stock* Raspberry Pi 400 and tried again. Fortunately, the compile (more-or-less) picked up where it died. After about 5 hours, the compile completed without errors. I now had executable binaries for mongod, mongos and mongo (the “old” Javascript shell).

I am providing the 4.4.8 binaries and 5.0.5 binaries to save folks time and effort.

MongoDB 4.4.8:
sha256: 1b50ab43f5ee39b74603563ce7c88ff2654338dca7ed58df24569900aaf44f08  raspbian_mongodb_4.4.8.gz

MongoDB 5.0.5:
sha256: 9eaf5797bf2a54ba73adb4652668dfe5bf0d54efc387053b6241a5e3c38c7cc9  raspbian_mongodb_5.0.5.gz

The usual disclaimers apply: use at your own risk, no warranties of any kind, your mileage may vary, etc.  Please do NOT directly link to the file.  You can link to this blog or specific blog entry.

Install and use

Ensure you are running the latest version of Raspbian64 OS with all updates. Download and unzip the raspbian_mongodb_4.4.8.gz or raspbian_mongodb_5.0.5.gz file.  You’ll have 3 files, mongod, mongos and mongo. Move the executables to /usr/bin and change owner and group to root.  Ensure permissions are set to executable.

For version 4.4.8:

tar zxvf raspbian_mongodb_4.4.8.gz
sudo mv mongo* /usr/bin
sudo chown root:root /usr/bin/mongo*
sudo chmod 755 /usr/bin/mongo*

Create the mongodb user.

sudo adduser --no-create-home --disabled-login mongodb

Create the configuration file:  /etc/mongodb.conf and add the following lines:

sudo vi /etc/mongodb.conf
# mongod.conf

# for documentation of all options, see:

# where to write logging data.
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
  dbPath: /data/db
    enabled: true
#  engine:
#  wiredTiger:

# network interfaces
  port: 27017
  bindIp:  # Enter,:: to bind to all IPv4 and IPv6 addresses





## Enterprise-Only Options



Create the log file and data directory. Change owner and group.

sudo mkdir -p /var/log/mongodb/
sudo chown -R mongodb:mongodb /var/log/mongodb/
sudo mkdir /data
sudo chmod 777 /data
sudo mkdir -p /data/db
sudo chown -R mongodb:mongodb /data/db

Create the systemctl service file to stop/start mongod process and add the following lines:

sudo vi /lib/systemd/system/mongodb.service
Description=An object/document-oriented database

# Other directives omitted
# (file size)
# (cpu time)
# (virtual memory size)
# (locked-in-memory size)
# (open files)
# (processes/threads)
ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf


You can now start/stop the mongodb service (mongod). Remember to stop gracefully before rebooting your system!

$ sudo service mongodb start

$ sudo service mongodb status

● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; disabled; vendor preset: enabled)
   Active: active (running) since Sat 2021-08-07 11:27:26 PDT; 1 day 1h ago
     Docs: man:mongod(1)
 Main PID: 1771 (mongod)
    Tasks: 33 (limit: 4164)
   CGroup: /system.slice/mongodb.service
           └─1771 /usr/bin/mongod --quiet --config /etc/mongodb.conf

You can also now run mongo, an interactive JavaScript shell interface to MongoDB

$ mongo

MongoDB shell version v4.4.8
connecting to: mongodb://
Implicit session: session { "id" : UUID("328da768-3ae6-4638-9df3-5fb4d32156ff") }
MongoDB server version: 4.4.8

> show databases;
admin   0.000GB
config  0.000GB
local   0.000GB

Let me know in the comments if you have issues or questions.

29 thoughts on “MongoDB 5.0 under Raspberry Pi OS (64-bit)”

  1. THANK YOU for building and distributing this. It works very well, and the steps are clear and concise.

    I am an experienced developer but very new to Linux/Raspberry, and I had no issues following the guide. I only got confused when creating the mongodb user, but it works well now.

    Have you done something similar for MongoDB version 5? I see their community version has a Debian 10 package available, will that work on the Raspberry Pi OS 64-bit?

  2. pi@esc:~ $ uname -a
    Linux esc 5.10.63-v7l+ #1488 SMP Thu Nov 18 16:15:28 GMT 2021 armv7l GNU/Linux

    pi@esc:~ $ /usr/bin/mongod –quiet –config /etc/mongodb.conf
    bash: /usr/bin/mongod: cannot execute binary file: Exec format error

  3. Hmmm, works OK for me! Please ensure you are using Raspbian 64 bit and have done an OS update/upgrade, Your bash command throws an error when I try it. I usually have mongodb as a service OR make it a background task. Using my binaries ( I see:

    pi@raspbian64:~ $ uname -a
    Linux raspbian64 5.10.88-v8+ #1504 SMP PREEMPT Wed Dec 22 14:22:56 GMT 2021 aarch64 GNU/Linux

    pi@raspbian64:~ $ which mongod

    pi@raspbian64:~ $ mongod –version
    db version v4.4.8
    Build Info: {
    “version”: “4.4.8”,
    “gitVersion”: “83b8bb8b6b325d8d8d3dfd2ad9f744bdad7d6ca0”,
    “openSSLVersion”: “OpenSSL 1.1.1d 10 Sep 2019”,
    “modules”: [],
    “allocator”: “tcmalloc”,
    “environment”: {
    “distarch”: “aarch64”,
    “target_arch”: “aarch64”

  4. having just iterated to a solution (go back and install 4.4 on an RP4 running Ubuntu 21.10), the hint over on Mongo is to cross compile 5 for ARM. So what would be the path to do that for 64 bit Ubuntu ?

    1. Hmmm, I’ve never been able to get a cross-compile working 🙁 What I do is a native compile on the R-Pi. Check out my instructions for compiling 4.4 on R-Pi and use the latest sources for 5.0.x. That’s what I did 🙂 Make sure you have 4-8GB RAM. If 4GB, ensure swap of 4GB. Takes some time but has worked for me on Ubuntu and Raspberry Pi OS 64-bit.

  5. Damn, I tried to build 5.0.6 on 4gb rpi 4, it kept sailing until I setup 8gb of swap, (failed with 2gb, so I guess something between 2 and 8gb of swap should be enough) also it took like… 16 hours to build? but it works just fine. thanks for the instructions. 🙂

  6. HiFiGuitarGuy

    Thanks for providing binaries – I suppose I’ll look to a DevOps pipeline to cross compile on something with more horsepower. Why hasn’t MongoDB done this? ¯\_(ツ)_/¯
    I’m pushing to my own Azure Container Repo, but for local Docker image:

    # Folder for cleanliness
    mkdir mongo_docker && cd mongo_docker

    # Get binaries and extract
    tar zxvf raspbian_mongodb_5.0.5.gz

    # Write Dockerfile
    echo “FROM arm64v8/mongo” >> Dockerfile
    echo “ADD mongo /bin/” >> Dockerfile
    echo “ADD mongos /bin/” >> Dockerfile
    echo “ADD mongod /bin/” >> Dockerfile
    # Trick the boilerplate mongo docker-entrypoint, trust our binaries regardless of cpuinfo (fphp -> fp) pattern match
    echo “RUN sed -i ‘s/fphp|dcpop|sha3|sm3|sm4|asimddp|sha512|sve/fp|dcpop|sha3|sm3|sm4|asimddp|sha512|sve/g’ /usr/local/bin/” >> Dockerfile

    # Docker Build
    docker build –tag mongo:5.0.5 .

    # Docker run-as service
    docker run -d –restart unless-stopped –name mongodb mongo:5.0.5

    1. Tried to build the Docker image but got error with echo “RUN sed -i ‘s/fphp|dcpop|sha3|sm3|sm4|asimddp|sha512|sve/fp|dcpop|sha3|sm3|sm4|asimddp|sha512|sve/g’ /usr/local/bin/” >> Dockerfile .. it does not know sm3 sm4 etc.. can you help me?

  7. Andy, thanks for the super helpful info. I am attempting to compile on my 8GB rpi4. Would you be willing to share the command line that you used to kick off the compile? This is what I am using:

    I did get it to compile to completion, but had not set the armv8-a flag. It did just bomb out complaining about CRC and I just barely based on a post add the +crc bit.

    python buildscripts/ install-mongod CCFLAGS=-march=armv8-a+crc –disable-warnings-as-errors

    1. Chet,

      I believe I used:

      python3 buildscripts/ --ssl CC=gcc-8 CXX=g++-8 CCFLAGS="-march=armv8-a+crc -mtune=cortex-a72" --install-mode=hygienic --install-action=hardlink --separate-debug archive-core{,-debug}

  8. Thank you! And thank you for providing all the steps needed to run it as a systemd service. Saved me three days and burn raspberry pi4!

  9. And btw. I guess the build runns concurrent buiild jobs (make -j(N)). On raspberry pi4 when i compile my c++ code I can often use -j2 for my own code but never above it unless i want to hit the swap file. Maybe disabling concurrent build jobs all together is better, to save the hardware from burning 🙂

  10. God bless you for providing the binaries. I was so sad when I finally got a mongo 5 docker container set up and it died with an illegial instruction and “WARNING: MongoDB 5.0+ requires ARMv8.2-A” in the logs.

  11. Pingback: DevOps in Action! - How We Built the DevDash Demo

  12. Thanks Andy, really you saved my day …
    I’m going to capture data from a mining process, whit Raspeberry pi sensors, and store it in MongoDB to apply deep learning models.

  13. Your Installation works very well! Thank you very much.

    But I have a question. I need Mongo 4.4. So I installed your binary with success. But no I have to install a debian package which is dependent on Mongodb. But apt doesn’t know, that this is installed as build and manually. Is there any way to say apt, that it is installed?

    Regards and congratulation for your excellent description!

  14. Hey Andy,
    thank you so much for putting this together. I was able to cross-compile mongo 5 and 6 (just the database), and I wanted to share my working binaries in this repo:
    Surely, I reference this site as a basic guide for setting up the binaries, config and daemon, as it is greatly explained.
    I hope this is useful to you and readers.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top