Installing or Updating the Newest Node.js

Installing or Updating the Newest Node.js

More of my projects have been using Node.js and Node-RED lately and I have found that Raspbian has an old version of Node installed. Plus, you cannot use the normal apt-get to get the updated version. Check out Stack Overflow for the reasons. I found there are two different ways to get the latest.

If you need to install Node.js and do not need Node-RED

The basic Rasbian instructions are found here. I used the Debian instructions but it required an extra step. To become root I used the following command and then the update ran without issue:
sudo su
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -y nodejs

Remember, this will uninstall Node-RED.

If you need Node.js and Node-RED

The kind folks at the Node-RED team have created a do-it-all script that will take care of everything. As the pi user, run update-nodejs-and-nodered. This will update Node.js to version 6 and Node-RED to the latest. To have Node-RED start on boot run sudo systemctl enable nodered.service. If you find the script is missing you either don’t have Node.js install or it is an old version. Not to worry. Th following command will download the latest script and perform the install/upgrade. Run this as the pi user.
bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

Installing on DietPi

If you are using the DietPi distribution things are a little easier. Just use the dietpi-software program to install the latest Node.js and Node-RED.