MongoDB plus Bionic Beaver on Pi

[UPDATED 05 Jan 2020] There is now an official Ubuntu 18.04 LTS image for Raspberry Pi 3. Install the arm64 image following instructions on the Ubuntu Wiki. You can then install MongoDB 4.2.x per this blog entry. NOTE that I still recommend adding swap space – as mentioned below.

[UPDATED 03 Nov 2019] Looking to run MongoDB 4.2.x on a Raspberry Pi 4? Check out this post. It is also 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 4.0.11 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 August 2019 is Ubuntu Server image for Raspberry Pi 3 (440MB 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 – so give it some time for first boot. The 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 Server 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-1041-raspi2 #44-Ubuntu SMP PREEMPT Wed Jul 3 15:45:20 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux

$ cat /etc/os-release



NAME="Ubuntu" VERSION="18.04.3 LTS (Bionic Beaver)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 18.04.3 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

Recent MongoDB docs (August 2019) say to use this method to get key, though either way should work:

wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add -

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.11 git version: 417d1a712e9f040d54beca8e4943edce218e9a8c 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.11 git version: 417d1a712e9f040d54beca8e4943edce218e9a8c 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. This install and configuration works for me BUT 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…