Running NightmareJS on CentOS 6

Most posts on this site aren’t exactly riveting to read, but they might just save you hours and hours of work.  This one is no different!

NightmareJS is fantastic, but due to its reliance on Electron and a strange mix of dependencies, getting it to work on CentOS is very involved.  Lucky for you, I’ve compiled all of the necessary commands and even compiled binaries/libraries to save you from losing what’s left of your hair.

These instructions have been tested on CentOS 6.7.

Install Prerequisites

X-related Packages

Xvfb is required to provide the pseudo-headless-X environment; libXScrnSaver is required to add libXss.so.1.

[root@backend ~]$ yum install xorg-x11-server-Xvfb libXScrnSaver

MS fonts

(More info: http://mscorefonts2.sourceforge.net/)

[root@backend ~]# yum install curl cabextract xorg-x11-font-utils fontconfig
 [root@backend ~]# rpm -i https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm

Upgrade gcc library

I’ve already done the hard work for you and compiled gcc 6.3 from source on CentOS 6.8, 64 bit.  Download the library at https://github.com/rinogo/gcc-6.3.0-lib-CentOS-6-build/raw/master/libstdc%2B%2B.so.6.0.22-CentOS-6.tar.gz.  Extract it to the home directory of whichever user you’re logged in as (in my case, root).  Then, install it using the following instructions:

[root@backend ~]# cd /usr/lib64/
 [root@backend lib64]# mv ~/libstdc++.so.6.0.22 .
 [root@backend lib64]# ls -alF libstdc++.so.6*
 lrwxrwxrwx 1 root root 19 Oct 1 2015 libstdc++.so.6 -> libstdc++.so.6.0.13*
 -rwxr-xr-x 1 root root 987096 Jul 22 2015 libstdc++.so.6.0.13*
 -rwxr-xr-x 1 root root 11508835 Apr 25 18:53 libstdc++.so.6.0.22*
 #Notice the symbolic link to 6.0.13
 [root@backend lib64]# rm libstdc++.so.6
 [root@backend lib64]# ln -s libstdc++.so.6.0.22 libstdc++.so.6
 [root@backend lib64]# ls -alF /usr/lib64/libstdc++.so.6*
 lrwxrwxrwx 1 root root 19 Apr 26 18:34 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.22*
 -rwxr-xr-x 1 root root 987096 Jul 22 2015 /usr/lib64/libstdc++.so.6.0.13*
 -rwxr-xr-x 1 root root 11508835 Apr 25 18:53 /usr/lib64/libstdc++.so.6.0.22*
 #Notice the symbolic link to 6.0.22
 [root@backend lib64]# cd
 [root@backend ~]# strings /usr/lib64/libstdc++.so.6 | grep GLIB

Before, we only had strings up until GLIBCXX_3.4.13, but now we have strings up until GLIBCXX_3.4.22. (Our version of Electron requires GLIBCXX_3.4.15)

Update glib library

Follow the nice instructions of some friendly gents over on GitHub to install an updated version of glib that will support Electron (NightmareJS).  More info: https://github.com/electron-userland/electron-prebuilt/issues/182#issuecomment-253279348

[root@backend ~]# cd /opt
 [root@backend opt]# wget https://jlison.github.io/bin/centos6/soichih/mirror/gcc-4.7.2.tar.gz
 [root@backend opt]# tar xzf gcc-4.7.2.tar.gz
 [root@backend opt]# rm gcc-4.7.2.tar.gz
 [root@backend opt]# cd /etc/ld.so.conf.d/
 [root@backend ld.so.conf.d]# nano gcc-4.7.2.conf

Into this file, paste the following:

/opt/gcc-4.7.2/glib-2.49.4-kgesagxmtbemim2denf65on4iixy3miy/lib
 /opt/gcc-4.7.2/libffi-3.2.1-wk2luzhfdpbievnqqtu24pi774esyqye/lib64
 /opt/gcc-4.7.2/pcre-8.39-itdbuzevbtzqeqrvna47wstwczud67wx/lib
 /opt/gcc-4.7.2/gettext-0.19.8.1-aoweyaoufujdlobl7dphb2gdrhuhikil/lib
[root@backend ld.so.conf.d]# ldconfig
 [root@backend ld.so.conf.d]# ldconfig -p | grep "libglib"

Check for glib-2.49.4.

Set up D-Bus library

This step might not be necessary.  On the first machine I performed these steps, I didn’t need to do this, but on the second one, I did.  When running your NightmareJS script, if you get an error about the D-Bus library not being set up correctly, execute this simple command (Thanks to Tork Wrench).

[root@backend ~]# dbus-uuidgen > /var/lib/dbus/machine-id

Finally – Running NightmareJS!

[dev@backend ~]$ cd project/
 [dev@backend your-project]$ rm -rf node_modules/
 [dev@backend your-project]$ npm install
 [dev@backend your-project]$ DEBUG=nightmare*,electron* xvfb-run -a --server-args="-screen 0 1280x2000x24" node your-script.js -- --progress=false --single-run --watch=false

Note – this is likely not the best command for you; in fact it almost certainly is not. Experimentation will be needed in adding/removing/changing flags.  However, this should hopefully be enough to verify that NightmareJS is in a functional state.

*I made it all the way through this post without making an obvious pun about how hard it is to get NightmareJS running on CentOS.  I hope I’ve made you proud!