In this tutorial, we will learn how to install NodeJs on any raspberry pi.
For those of you that would prefer a video, here’s one that I prepared earlier: https://www.youtube.com/watch?v=oFdlRcRl5aQ
Different versions of the raspberry pi sometimes require different versions of node. So to make things simple, we’re just going to use a script that will handle all of the complexities for us. The script and the details about it can be found at https://github.com/meech-ward/NodeJs-Raspberry-Pi.
Don’t use nvm
A quick aside for anyone wondering why we’re not using nvm here. NVM doesn’t work well with
sudo, and it helps to be able to run a script on the raspberry pi with
sudo. You can still use nvm with sudo but it usually involves something weird like
sudo $(which node) script.js, and deamon services are awkward. It’s better just to install it without nvm.
Before installing node, you need to have your raspberry pi setup and access to the pi’s terminal. If you need help getting setup, check out my getting started videos: https://sammeechward.com/raspberry-pi-for-developers-getting-started/
The following code comes straight from https://github.com/meech-ward/NodeJs-Raspberry-Pi
Copy the following line of code and paste it into your terminal:
wget -O - https://raw.githubusercontent.com/meech-ward/NodeJs-Raspberry-Pi/master/Install-Node.sh | sudo bash
Hit enter to install node. This should only take a moment.
That’s it, node js should be installed and ready to go.
We can test this out by typing in
var greeting = "Hello Pi"; console.log(greeting);
Press control + d to get out of there.