MongoDB plus Bionic Beaver on Pi

it is now possible to run Ubuntu 18.04.2 (ARM 64-bit) directly on the Raspberry Pi 3. You can read more about this and get SD Card images from the Ubuntu wiki. I am using the server version of “Ubuntu Classic” as opposed to the new “Snappy Ubuntu Core.” MongoDB has an official release of MongoDB 4.0.6 for “Ubuntu 16.04 Linux 64-bit ARM 64.” I will show how to install this version of MongoDB under Ubuntu 18.04 on the Raspberry Pi 3B+. These instructions should work for any version of R-Pi 3 but I have only tested on my Raspberry Pi 3B+.

Download the ARM64 image for the Raspberry Pi 3 as instructed on the Ubuntu Wiki. The download link as of 01 March, 2019 is ubuntu-18.04.2-preinstalled-server-arm64+raspi3.img.xz (4G image, 419MB compressed). This is an R-Pi image that needs to be written to the Micro SD Card – as usual. It is important to read the install directions on the wiki!

Note that you might see key-exchanges going on at first boot. The file system also auto-expands. The first login/password is ubuntu/ubuntu. You will be prompted to change. “raspi-config” does NOT work! I am using the ethernet connection so no network configuration is required. WiFi is supported under Ubuntu 18.04 but is not the easiest to setup — and is beyond the scope of this post — read the docs 😉

After a successful boot, make sure your OS is up to date:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

Here are my versions of name, kernel & OS info:

$ uname -a

Linux ubuntu 4.15.0-1031-raspi2 #33-Ubuntu SMP PREEMPT Wed Jan 16 09:52:45 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux

$ cat /etc/os-release

NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

OK, let’s install the MongoDB Community Server and utilities.

Import the public key for the Package Management System:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Add a MongoDB list file from the “xenial” branch as MongoDB 4 is not yet in the “bionic” branch. Update the packages list.  Install any updates and then install MongoDB.  Note that “lincurl4” replaced “libcurl3” in Ubuntu 18.04.  We need to revert to “libcurl3” for MongoDB 4.0 to install correctly.  A simple “apt-get install” will do the trick.

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libcurl3
sudo apt-get install -y mongodb-org

You can check versions installed:

mongod --version

db version v4.0.6
git version: caa42a1f75a56c7643d0b68d3880444375ec42e3
OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: aarch64
    target_arch: aarch64

mongo --version

MongoDB shell version v4.0.6
git version: caa42a1f75a56c7643d0b68d3880444375ec42e3
OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: aarch64
    target_arch: aarch64

Before running MongoDB, I add 2GB system swap space. This can slow things down considerably but I have, on occasion, had issues with some utilities such as “mongoimport” if I did not add space. Most of the time, swap space is not used and doesn’t impose a performance penalty. You could try running MongoDB (mongod, mongo) without swap but be aware of this swap option if things seem to hang.

sudo dd if=/dev/zero of=/swapfile.img bs=1M count=2048
sudo mkswap /swapfile.img
sudo swapon /swapfile.img
cat /proc/swaps

You can start MongoDB and check its status:

sudo service mongod start
sudo service mongod status

Run the MongoDB shell:

mongo

I have run much of the MongoDB Javascript Test Suite as found on GitHub without errors or issues. This does not mean this write-up will work for you. I would NOT use this configuration in a production environment. It does, however, work for me and I do regular backups/exports (dumps and JSON) that I could migrate to another system – if ever needed. As always, your mileage may vary! Please LMK in comments if you have questions or issues…