4

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
Marius Miliunas
  • 1,023
  • 18
  • 34
  • Check out http://bushrobot.blogspot.com/2012/01/node-068-refuses-to-build-on-centos-5.html – Ryan Olds Aug 15 '12 at 17:52
  • I tried that with Python 2.6, no beans. I installed Python 2.7.3, which does not have that line in it's make file. Tried configing, then making, and at the end of the make script, it returns 'Failed to build these modules: bz2' – Marius Miliunas Aug 15 '12 at 18:57
  • 2
    Do you have bzip2-devel and/or libbz2-dev installed? I may have the package names slightly wrong, varies by distro. Python probably needs all the dev stuff to build it's module. – Ryan Olds Aug 15 '12 at 19:08
  • I do. I installed them all using the yum command – Marius Miliunas Aug 15 '12 at 19:12
  • edit: I started make'ing 2.7.3 but 2.6.7 is still my default. They're both having an issue finding bz2 even though it's installed, so I'm completely lost – Marius Miliunas Aug 15 '12 at 19:28
  • 1
    Ended up doing everything you guys posted, and everything I could find on getting bzip2 to work, no matter what I did, Python2.6.7 could not find it, so I replaced it with Python 2.7.3, and voila it worked. Also found this link useful https://github.com/joyent/node/issues/3504 – Marius Miliunas Aug 16 '12 at 13:40
  • Please be adding an answer to make it easier for people to find the solution. Thanks you for updating with your solution. Not everyone does that. – Ryan Olds Aug 16 '12 at 20:25
  • I don't have a clean cut solution. I scoured the web for hours running tons of snippets that people posted. I don't know which one's did anything towards my solution, I just know that I couldn't get this running on Python 2.6.7 no matter what I did. The link I posted is the closest to any solution i found. Sorry I can't be of more help. – Marius Miliunas Aug 17 '12 at 18:10
  • Make sure to rebuild python *after* installing bzip2-devel. – Doug Harris Apr 18 '13 at 21:01

2 Answers2

3

Note that another solution to this issue (unable to compile node.js) is to use the binary distributions for Linux which have been published since 0.8.6

Here's the script I used:

# get the latest stable binary 
# (modify version number based on what you find in that folder)
wget http://nodejs.org/dist/latest/node-v0.8.20-linux-x64.tar.gz
cd /usr/local/
sudo tar xzvf ~/node-v0.8.20-linux-x64.tar.gz --strip=1
explunit
  • 18,967
  • 6
  • 69
  • 94
3

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.

Vietnhi Phuvan
  • 2,704
  • 2
  • 25
  • 25