[manjaro] compile MongoDB from source and install it manually
I wanted to install MongoDB on an old 32-bit laptop of mine. After installing it from the official repository, the mongo shell died with the following error: ” Illegal instruction (core dumped)”.
The problem is that the binary file uses an instruction set that is not supported by my old 32-bit CPU:
$ cat /proc/cpuinfo | grep flags flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss tm pbe nx bts est tm2
SSE3 is missing :( What to do? Uninstall the mongodb package and 1) compile it from source, 2) install it and 3) make it start at startup.
(1) Compile the source
I found an excellent blog post about it at http://kdenby.homelinux.com/?p=25 . Here I would sum up the steps.
Download the source from here: https://www.mongodb.org/downloads . It’s about 35 MB. The source uses the SCons build system, so install the “scons” package too. Note that the compilation process took about 6 hours on my old laptop and the work directory where compilation was being done grew to 18 GB! I didn’t have that much free space so I had to move this work directory to an external HDD :) However, when you install the binaries, they will only occupy 90 MB.
So, if you have an old CPU, edit the file
if using_gcc() or using_clang(): myenv.Append( CCFLAGS=['-march=pentium3', '-mtune=generic'] ) #myenv.Append( CCFLAGS=['-march=nocona', '-mtune=generic'] )
The target architecture “nocona” was replaced by “pentium3”. Again, this tip is from Karl.
After this you can start the compilation and wait :)
$ scons --disable-warnings-as-errors --32 all
The blog post at http://kdenby.homelinux.com/?p=25 stops at this point.
(2) Install the binaries
I installed the binaries to
$ scons --prefix=/opt/mongo-3.0.5 install
Of course, replace “3.0.5” with your current version. I also put a symbolic link on this folder:
$ cd /opt $ ln -s mongo-3.0.5 mongo
Note that the binaries are put into a “
bin” folder, thus they are located in “
Now put symbolic links in
/usr/bin/ that point to the appropriate binaries in
/opt/mongo/bin/. They look like this on my machine:
$ cd /usr/bin $ ls -al | grep mongo lrwxrwxrwx 1 root root 20 11.08.2015 08:30 mongo -> /opt/mongo/bin/mongo lrwxrwxrwx 1 root root 21 11.08.2015 08:31 mongod -> /opt/mongo/bin/mongod lrwxrwxrwx 1 root root 24 11.08.2015 08:31 mongoperf -> /opt/mongo/bin/mongoperf lrwxrwxrwx 1 root root 21 11.08.2015 08:31 mongos -> /opt/mongo/bin/mongos lrwxrwxrwx 1 root root 25 11.08.2015 08:31 mongosniff -> /opt/mongo/bin/mongosniff
(3) Make MongoDB start at startup
Create these two directories:
/var/log/mongodb . The mongo daemon shouldn’t run with root privileges, so we create a dedicated user for this purpose and set its password:
$ sudo adduser mongodb $ sudo passwd mongodb
Now, the owner of the previously created two folders will be “
mongodb“, and they will belong to the “
daemon” group. Example on my machine:
$ cd /var/log $ ls -al | grep mongodb drwxr-xr-x 2 mongodb daemon 4096 11.08.2015 09:29 mongodb/
After this, you need to copy some config files as root. They are collected here.
/etc/mongodb.conf . Mine looks like this:
# See http://www.mongodb.org/display/DOCS/File+Based+Configuration for format details # Run mongod --help to see a list of options bind_ip = 127.0.0.1 quiet = true dbpath = /var/lib/mongodb logpath = /var/log/mongodb/mongod.log logappend = true noprealloc = true smallfiles = true
/usr/lib/systemd/system/mongodb.service . Sample:
[Unit] Description=High-performance, schema-free document-oriented database After=network.target [Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf [Install] WantedBy=multi-user.target
Now it’s time to enable and start the mongodb service:
$ systemctl enable mongodb.service $ systemctl start mongodb.service
Verify if it’s running:
$ systemctl status mongodb.service
If it seems OK, try to connect to it with the mongo shell using the command “
If the service doesn’t start with the
systemctl command, then try to launch the server manually:
$ mongod --quiet --config /etc/mongodb.conf
You may want to remove the “
--quiet” option. If it has some problems, it will print a more detailed error message than “
I wrote this post one week after I installed MongoDB, but I hope I didn’t forget any steps. Good luck!
For compiling version 3.2.0, I used the following steps:
scons --wiredtiger=off --disable-warnings-as-errors mongo mongod strip mongo strip mongod
The compilation was too long, so I narrowed it down to mongo and mongod only. The resulting binaries were huge, but the command strip did the trick by removing the debug symbols.