Do you want to install Node.js on your Raspberry Pi? It’s actually quite a bit easier than it used to be. I just recently installed Node.js 0.8.16 on my Raspberry Pi and decided to document it. For this tutorial I’m using a setup with the latest Raspian image.
Installation of Node.Js 0.8.16
Other Raspberry Pi Stuff
- Set up a Raspberry Pi Web Server
- Raspberry Pi Web Server Speed Test
- How to Overclock Raspberry Pi
- How to Install Node.js on RPi
- How to Build a Raspberry Pi File Server
To do this, you’ll need to build Node.js from source. It’s not as bad as it sounds, and actually pretty easy. We’ll be getting the source from the downloads page at Nodejs.org and compiling it from there.
For this tutorial I’m using the Raspian “Wheezy” Image but since we’re compiling from source it shouldn’t matter too much what version you’re using.
You’ll want to go into your /usr/src directory (or some temporary directory) and use wget to download the file.
This will pull down the source tarball to your machine. You must have your Raspberry Pi connected to the internet, if you don’t then download the file here and put it on your Pi.
Next steps will build the program:
1 2 3
Note: The make process can take quite a while, well over an hour in most cases. You may want to start the build and do something else, or if you’re in a hurry you can overclock your Pi to make it build a little faster.
Testing your Node.js Install
Once it’s built, if you don’t see any errors, it should be ready to go. You can run some tests with the following command:
Not all of the tests will pass, but most of them should. For a quick web test, put the following code in a file called test.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
And save it. Then run the following command:
And then point your web browser to http://127.0.0.1:8000 and you will see a hello world! message.
I hope this helps folks wanting to try out node on their Raspberry Pi. In the past it was a bit tricky and for some people compiling from source can scary. But as you can see this is a pretty straightforward process.
While it may not be the best node server to use it’s great for a development environment, as most hosting companies do not offer Node.js yet. The Raspberry Pi is designed for learning and experimenting and provides a great easy platform to do that.
So get out there and start building some node apps with non-blocking goodness!