Installing Node.js (Raspberry Pi / JavaScript)

During winter 2017 I went through the process of using a Raspberry Pi, as a web server / looking at LAMP (Linux, Apache, MySQL, PHP). With my recent interest in JavaScript I have decided to look at installing Node.js on my Raspberry Pi.

Node.js is a free open source environment for running JavaScript on a server, rather than JavaScript in a web browser.

First things first, for this little project I am using:

A Rasperry Pi 3 – as it has built in WiFi. A different Raspberry Pi can be used but please note the Pi, Pi 2 and Pi Zero all require either a physical connection or a WiFi adapter. Also please note that the Pi 3 uses an ARM v8 processor where as the other Pi models (e.g. the Pi 2) do not.

Raspbian OS – currently my Pi is running Raspbian Stretch (released June 2018). If you are using a different version of Raspbian then there may be some changes needed to get Node.js working.

nodejs_pi_1.png

I am connecting to my Pi via SSH, however the same terminal instructions can be used directly on the Pi. I prefer using SSH as it frees me up from being near the television (where the Pi is connected) and frees the TV up for others in the house to use. On a side note, if you are using SSH please make sure you have followed good security practise and have changed the default Pi password.

nodejs_pi_2.png

With SSH connected I recommended making sure that the Pi’s update catalog is up to using the sudo apt-get update command, and that the Pi is then up to date using the sudo apt-get upgrade command.

nodejs_pi_3.png

With everything up to date it is time to let the Pi know where to get Node.js from. Raspbian is part of the Debian Linux family, as such it has repositories containing information about packages/applications. To let Raspbian know where to get Node.js from the following command is needed:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash –

nodejs_pi_4.png

Raspbian now knows about Node.js and where to get it but has not yet installed it. To install Node.js the following command is needed:

sudo apt-get install -y nodejs

nodejs_pi_5.png

As long as no error messages occur, Node.js should now be installed on the Raspberry Pi. To test that Node.js is installed and check which version is installed we can enter the following command:

node -v

nodejs_pi_6.png

The above shows that v8.12.0 is installed on the Raspberry Pi.

Node.js is now ready for use! Node.js can be launched by typing node at the terminal and can be exited by typing .exit or by pressing CTRL C (twice).

node_pi_7.png

Useful Links:

Node.js Official Site:

https://nodejs.org/en/

Raspbian OS Download:

https://www.raspberrypi.org/downloads/raspbian/

Wikipedia page about Node.js:

https://en.wikipedia.org/wiki/Node.js

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s