Search code examples
node.jscentos5bzip2

Error installing Nodejs on CentOS 5 server - no module bz2


I'm trying to get NodeJS installed on my CentOS 5 server

I got Python 2.6 installed, and I got ./configure to work, but when I run the make command I get this result

[root@catch24dev node-v0.8.6]# make
make -C out BUILDTYPE=Release V=1

....

Traceback (most recent call last):
  File "../../tools/js2c.py", line 36, in <module>
    import bz2
ImportError: No module named bz2
make[1]: *** [/usr/local/src/node-v0.8.6/out/Release/obj/gen/libraries.cc] Error 1
make[1]: Leaving directory `/usr/local/src/node-v0.8.6/out'
make: *** [node] Error 2
[root@catch24dev node-v0.8.6]# which bzip2
/usr/local/bin/bzip2

Solution

  • I, too, got the same error as Marius Milliunas when I ran make on Centos 6.4 - That was after I ran the ./configure command in the nodejs directory, which I had extracted from the downloaded nodejs tarball. Just as Marius Milliunas did.

    The root of the problem is that the nodejs installation relies on Python being installed. Specifically, the default Python installation for Centos 6.4 does NOT include the bz2 module and corrective action, of course, starts with installing the bz2 module. This is done by running

    yum install bzip2-devel
    

    I also ran for good measure

    yum install bzip2 
    

    The built-in Python for Centos 6.4 is Python 2.6.6 but that's fine for the purpose of installing the latest version of nodejs, which as of this writing is node v0.10.26

    Once you have run yum install bzip2-devel , you can go back and run make in the nodejs directory and this time, make will run to completion. Follow up by running make install as per the instructions set in the nodejs directory.

    You can test your nodejs installation by running node and getting the prompt. I chose to test by creatind a nodejs-based web server, as described in http://code.tutsplus.com/tutorials/real-time-chat-with-nodejs-socketio-and-expressjs--net-31708

    I knew all was cool with the world and that I had properly installed nodejs on Centos 6.4 when I followed this instruction

    The server is running, so you should be able to open http://127.0.0.1:3700/ and see:
    
    It works!
    

    and got the "It works" output, as expected :)

    Important Note

    If you are additionally installing Python 2.7.6 and Python 3.3.4 on the Centos 6.4 machine, follow the instructions on this link: https://www.digitalocean.com/community/articles/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4

    Installing Python 2.7.6 and Python 3.3is purely optional. Note that the last step of installing Python 2.7.6 and Python 3.3.4 is

    make altinstall
    

    and NOT "make install" I ran "make install" by mistake and destroyed my access to system Python, which is Python 2.6.6, and my access to yum. In fact, I surmise that I destroyed my access to every program on Centos 6.4 that relies on access to system Python to work properly. If I had successfully installed nodejs by that point in time, I would have destroyed my access to nodejs, too. I had to destroy and recreate /usr/local/bin/python2 as the soft link to /usr/local/bin/python2.6 and do the same with /usr/bin/python2 to get things back to normal. Not much fun.