StuartMVG
Posts: 1
Joined: Fri Mar 25, 2016 5:59 pm

How to install Node.js on Raspberry Pi 3?

Fri Mar 25, 2016 6:17 pm

What is the best way to install Node.js on a Raspberry Pi 3?
Is it the same as on a 2, if so what is the best way?
If not, what do I do differently?

Now this maybe a very basic question, but since this is my first experience with a Pi and a Linux OS, I want to make sure I get it right.

Thank you,
Stuart

flowersj
Posts: 2
Joined: Sun Aug 31, 2014 4:28 am

Re: How to install Node.js on Raspberry Pi 3?

Sat Mar 26, 2016 12:23 am

I saw this:

https://blog.wia.io/installing-node-js- ... berry-pi-3

However, I noticed that they picked the armv6. Doesn't the rPi 3 have armv8 instruction set. Would the armv7 be 'faster' than the armv6 that the above tutorial recommend?

This post (viewtopic.php?f=63&t=99963) and reading through the full benchmarks; it seems that perhaps raspbian is/isn't fully optimized for armv7? Or is it now?

User avatar
kusti8
Posts: 3441
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: How to install Node.js on Raspberry Pi 3?

Sat Mar 26, 2016 12:28 am

There is no noticeable speed boost in ARMv7 instead of ARMv6
There are 10 types of people: those who understand binary and those who don't.

asandford
Posts: 1996
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: How to install Node.js on Raspberry Pi 3?

Sat Mar 26, 2016 12:28 am

Raspbian has node installed, but it's quite old.

To get to a more recent version:

Code: Select all

    [email protected]:~ $  node -v
    v0.10.29
    [email protected]:~ $  sudo su -
    [email protected]:~ # apt-get remove nodered -y
    [email protected]:~ # apt-get remove nodejs nodejs-legacy -y
    [email protected]:~ # apt-get remove npm  -y # if you installed npm
    [email protected]:~ # curl -sL https://deb.nodesource.com/setup_5.x | sudo bash -
    [email protected]:~ # apt-get install nodejs -y
    [email protected]:~ # node -v
    v5.9.0
    [email protected]:~ # npm -v
    3.7.3

elgervb
Posts: 1
Joined: Sun Oct 02, 2016 9:49 pm

Re: How to install Node.js on Raspberry Pi 3?

Sun Oct 02, 2016 9:52 pm

It's better to not install NodeJS directly, but to use NVM for that. This way, switching NodeJS versions is very simple.

Please see my Github repository on how to do that: https://github.com/elgervb/raspberrypi/ ... /nodejs.sh

Good luck with it ;-)

audstanley
Posts: 9
Joined: Fri Nov 28, 2014 12:44 am

Re: How to install Node.js on Raspberry Pi 3?

Tue Dec 27, 2016 9:30 pm

This will work for EVERY raspberry pi (zero|1|2|3|zero-w)
And will install the latest version of node. It's always up to date.

Code: Select all

sudo wget -O - https://raw.githubusercontent.com/audstanley/NodeJs-Raspberry-Pi/master/Install-Node.sh | bash;
node -v;
source code here: https://github.com/audstanley/NodeJs-Raspberry-Pi

...and no it doesn't install Node v4.2.6 (post below). It installs the Latest version of Node.
Last edited by audstanley on Fri May 12, 2017 4:15 pm, edited 8 times in total.

User avatar
IgorGanapolsky
Posts: 33
Joined: Sun Apr 10, 2016 8:32 pm

Re: How to install Node.js on Raspberry Pi 3?

Tue Mar 14, 2017 6:38 pm

audstanley wrote:This will work for EVERY raspberry pi (zero|1|2|3)
The above git repo only installs Node v4.2.6.
This guide is more up-to-date with v7:
http://thisdavej.com/upgrading-to-more- ... pberry-pi/

asandford
Posts: 1996
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: How to install Node.js on Raspberry Pi 3?

Tue Mar 14, 2017 9:44 pm

IgorGanapolsky wrote: This guide is more up-to-date with v7:
That might break Node Red flows
From here
Note: Node.js 7.x is under active development and is not recommended for a stable base. Many 3rd party node packages may not yet fully support Node 7.x and later, especially if they contain a binary component. Check with the author of the package if you are not sure.


dannymcvey
Posts: 5
Joined: Sat Apr 01, 2017 10:48 am

Re: How to install Node.js on Raspberry Pi 3?

Sat Apr 01, 2017 10:50 am

I've installed Node.js multiple times without issues on my Raspberry Pi 3 with the following commands:

Code: Select all

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
Source: https://nodejs.org/en/download/package- ... tributions

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How to install Node.js on Raspberry Pi 3?

Sat Apr 01, 2017 9:21 pm

dannymcvey wrote:installed Node.js without issues
can you confirm that NODE RED is still running?

dannymcvey
Posts: 5
Joined: Sat Apr 01, 2017 10:48 am

Re: How to install Node.js on Raspberry Pi 3?

Sun Apr 02, 2017 3:34 am

KLL wrote: can you confirm that NODE RED is still running
Negative. I saw this in the output upon updating the preinstalled version of Node.

Code: Select all

Removing nodered (0.15.3) ...
Removing nodejs-legacy (0.10.29~dfsg-2) ...

asandford
Posts: 1996
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: How to install Node.js on Raspberry Pi 3?

Sun Apr 02, 2017 3:48 am

KLL wrote:can you confirm that NODE RED is still running?
No, there are problems:

Code: Select all

[email protected]:~ $ node -v
v7.8.0
[email protected]:~ $ npm -v
4.2.0
[email protected]:~ $ [email protected]:~ $ sudo node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.0.45:1880
On Pi Node-RED works better with the Firefox browser

Use   node-red-stop                          to stop Node-RED
Use   node-red-start                         to start Node-RED again
Use   node-red-log                           to view the recent log output
Use   sudo systemctl enable nodered.service  to autostart Node-RED at every boot
Use   sudo systemctl disable nodered.service to disable autostart on boot

To find more nodes and example flows - go to http://flows.nodered.org

Started Node-RED graphical event wiring tool..
Welcome to Node-RED
===================
2 Apr 03:24:29 - [info] Node-RED version: v0.14.6
2 Apr 03:24:29 - [info] Node.js  version: v7.8.0
2 Apr 03:24:29 - [info] Linux 4.4.50-v7+ arm LE
2 Apr 03:24:29 - [info] Loading palette nodes
pi : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/python -u /usr/lib/node_modules/node-red/nodes/core/hardware/nrgpio.py info
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session closed for user root
2 Apr 03:24:33 - [info] Dashboard started at /ui
2 Apr 03:24:33 - [warn] ------------------------------------------------------
2 Apr 03:24:33 - [warn] [serialport] Error: The module '/usr/lib/node_modules/node-red/node_modules/node-red-node-serialport/node_modules/serialport/build/Release/serialport.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 51. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).
2 Apr 03:24:33 - [warn] [sensehat] Error: Can't find Sense HAT python libraries. Run sudo apt-get install sense-hat
2 Apr 03:24:33 - [warn] ------------------------------------------------------
2 Apr 03:24:33 - [info] Settings file  : /home/pi/.node-red/settings.js
2 Apr 03:24:33 - [info] User directory : /home/pi/.node-red
2 Apr 03:24:33 - [info] Flows file     : /home/pi/.node-red/flows_bootserver.json
2 Apr 03:24:33 - [info] Server now running at http://127.0.0.1:1880/
2 Apr 03:24:33 - [info] Waiting for missing types to be registered:
2 Apr 03:24:33 - [info]  - serial-port (provided by npm module node-red-node-serialport)
2 Apr 03:24:33 - [info]  - serial out (provided by npm module node-red-node-serialport)
2 Apr 03:24:33 - [info]  - serial in (provided by npm module node-red-node-serialport)
2 Apr 03:24:33 - [info] To install any of these missing modules, run:
2 Apr 03:24:33 - [info]   npm install <module name>
2 Apr 03:24:33 - [info] in the directory:
2 Apr 03:24:33 - [info]   /home/pi/.node-red
It can be made to work, but I've not tested that it works;

Code: Select all

[email protected]:~# node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.0.45:1880
On Pi Node-RED works better with the Firefox browser

Use   node-red-stop                          to stop Node-RED
Use   node-red-start                         to start Node-RED again
Use   node-red-log                           to view the recent log output
Use   sudo systemctl enable nodered.service  to autostart Node-RED at every boot
Use   sudo systemctl disable nodered.service to disable autostart on boot

To find more nodes and example flows - go to http://flows.nodered.org

Started Node-RED graphical event wiring tool..
2 Apr 03:52:10 - [info]
Welcome to Node-RED
===================
2 Apr 03:52:10 - [info] Node-RED version: v0.16.2
2 Apr 03:52:10 - [info] Node.js  version: v7.8.0
2 Apr 03:52:10 - [info] Linux 4.4.50-v7+ arm LE
2 Apr 03:52:11 - [info] Loading palette nodes
pi : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/python -u /usr/lib/node_modules/node-red/nodes/core/hardware/nrgpio.py info
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session closed for user root
2 Apr 03:52:15 - [info] Dashboard started at /ui
2 Apr 03:52:15 - [warn] ------------------------------------------------------
2 Apr 03:52:15 - [warn] [sensehat] Error: Can't find Sense HAT python libraries. Run sudo apt-get install sense-hat
2 Apr 03:52:15 - [warn] ------------------------------------------------------
2 Apr 03:52:15 - [info] Settings file  : /home/pi/.node-red/settings.js
2 Apr 03:52:15 - [info] User directory : /home/pi/.node-red
2 Apr 03:52:15 - [info] Flows file     : /home/pi/.node-red/flows_bootserver.json
2 Apr 03:52:15 - [info] Server now running at http://127.0.0.1:1880/
2 Apr 03:52:15 - [info] Starting flows
2 Apr 03:52:15 - [info] Started flows
2 Apr 03:52:15 - [info] serial port /dev/ttyS0 opened at 9600 baud 8N1


asandford
Posts: 1996
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: How to install Node.js on Raspberry Pi 3?

Sun Apr 02, 2017 4:05 am

dannymcvey wrote:Negative. I saw this in the output upon updating the preinstalled version of Node.

Code: Select all

Removing nodered (0.15.3) ...
Removing nodejs-legacy (0.10.29~dfsg-2) ...
I didn't get those, as I'd previously upgraded to a supported version, and installed NR with npm not apt.

dannymcvey
Posts: 5
Joined: Sat Apr 01, 2017 10:48 am

Re: How to install Node.js on Raspberry Pi 3?

Sun Apr 02, 2017 5:02 am

asandford wrote:I didn't get those, as I'd previously upgraded to a supported version, and installed NR with npm not apt.
Naturally, seeing we ran different commands.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How to install Node.js on Raspberry Pi 3?

Sun Apr 02, 2017 9:40 am

so on a new system ( with running NODE-RED )
better use this WAY-A from viewtopic.php?p=1106738#p1106738 because it not makes problems.
and i just confirm by install also v7.8 this way ( over a v7.4):
node -v v7.8.0
npm -v 4.2.0

and node-red say its using node v7.8.0

miguej
Posts: 9
Joined: Fri May 27, 2016 7:37 pm

Re: How to install Node.js on Raspberry Pi 3?

Wed Oct 25, 2017 9:11 pm

dannymcvey wrote:
Sat Apr 01, 2017 10:50 am
I've installed Node.js multiple times without issues on my Raspberry Pi 3 with the following commands:

Code: Select all

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
Source: https://nodejs.org/en/download/package- ... tributions
I've done that way in raspbian stretch but if I type 'node' or 'npm' obtained the old versions. I had to 'apt remove node' in order to use the new npm version

See:

Code: Select all

[email protected] ~ $ npm -v
2.5.1
[email protected] ~ $ node -v
v0.12.1
[email protected] ~ $ nodejs -v
v6.11.5
but if I try "sudo npm install -g cordova" (for example)...

Code: Select all

npm WARN engine [email protected]: wanted: {"node":">=4.0.0"} (current: {"node":"0.12.1","npm":"2.5.1"})
So, as I said before, I had to 'apt remove node'...and no problems after that.

RonR
Posts: 278
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: How to install Node.js on Raspberry Pi 3?

Wed Oct 25, 2017 10:48 pm

miguej wrote:
Wed Oct 25, 2017 9:11 pm
dannymcvey wrote:
Sat Apr 01, 2017 10:50 am
I had to 'apt remove node' in order to use the new npm version
FWIW...

Doing a build of FreePBX starting from a fresh Raspbian Stretch Lite image and installing the latest node.js using:

Code: Select all

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
apt-get -y install nodejs

## Installing the NodeSource Node.js v8.x repo...
## Populating apt-get cache...
+ apt-get update
Hit:1 http://mirrordirector.raspbian.org/raspbian stretch InRelease
Hit:2 http://archive.raspberrypi.org/debian stretch InRelease
[1 InRelease gpgv 15.0 kB]
Hit:3 http://mirrordirector.raspbian.org/raspbian jessie InRelease
[1 InRelease gpgv 15.0 kB]
[2 InRelease gpgv 25.3 kB]
[3 InRelease gpgv 14.9 kB]
## Confirming "stretch" is supported...
+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_8.x/dists/stretch/Release'
## Adding the NodeSource signing key to your keyring...
+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
OK
## Creating apt sources list file for the NodeSource Node.js v8.x repo...
+ echo 'deb https://deb.nodesource.com/node_8.x stretch main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src https://deb.nodesource.com/node_8.x stretch main' >> /etc/apt/sources.list.d/nodesource.list
## Running `apt-get update` for you...
+ apt-get update
Hit:1 http://archive.raspberrypi.org/debian stretch InRelease
[1 InRelease gpgv 25.3 kB]
Hit:2 http://mirrordirector.raspbian.org/raspbian stretch InRelease
[1 InRelease gpgv 25.3 kB]
Hit:3 http://mirrordirector.raspbian.org/raspbian jessie InRelease
[1 InRelease gpgv 25.3 kB]
[2 InRelease gpgv 15.0 kB]
Get:4 https://deb.nodesource.com/node_8.x stretch InRelease [4,647 B]
[2 InRelease gpgv 15.0 kB] [4 InRelease 4,647 B/4,647 B 100%]
[2 InRelease gpgv 15.0 kB]
[3 InRelease gpgv 14.9 kB]
[4 InRelease gpgv 4,647 B]
Get:5 https://deb.nodesource.com/node_8.x stretch/main Sources [762 B]
[5 Sources 762 B/762 B 100%]
[5 Sources store 0 B]
Get:6 https://deb.nodesource.com/node_8.x stretch/main armhf Packages [1,002 B]
[6 Packages 1,002 B/1,002 B 100%]
[6 Packages store 0 B]
Fetched 6,411 B in 2s (2,682 B/s)
## Run `apt-get install nodejs` (as root) to install Node.js v8.x and npm
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 11.2 MB of archives.
After this operation, 53.8 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_8.x stretch/main armhf nodejs armhf 8.8.0-1nodesource1 [11.2 MB]
Fetched 11.2 MB in 4s (2,411 kB/s)
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_8.8.0-1nodesource1_armhf.deb ...
Unpacking nodejs (8.8.0-1nodesource1) ...
Setting up nodejs (8.8.0-1nodesource1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Without any 'apt remove node', I see:

Code: Select all

[email protected]:/home/pi# npm -v
5.4.2
[email protected]:/home/pi# node -v
v8.8.0
[email protected]:/home/pi# nodejs -v
v8.8.0

miguej
Posts: 9
Joined: Fri May 27, 2016 7:37 pm

Re: How to install Node.js on Raspberry Pi 3?

Thu Oct 26, 2017 9:51 pm

Doing a build of FreePBX starting from a fresh Raspbian Stretch Lite image and installing the latest node.js using:
In my case: Raspbian Stretch upgraded from Raspbian Jessie (and could be even from Wheezy before, not sure...)

Code: Select all

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
apt-get -y install nodejs
[/quote]

And here I've used the https://deb.nodesource.com/node_6.x version, not the 7.x or 8.x ...maybe that's why...

RonR
Posts: 278
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: How to install Node.js on Raspberry Pi 3?

Fri Oct 27, 2017 1:27 am

miguej wrote:
Thu Oct 26, 2017 9:51 pm
And here I've used the https://deb.nodesource.com/node_6.x version, not the 7.x or 8.x ...maybe that's why...
Today, during an apt-get upgrade, it went from 8.8.0 to 8.8.1

joeybronzoni
Posts: 3
Joined: Sun Nov 05, 2017 7:23 pm

Re: How to install Node.js on Raspberry Pi 3?

Fri Nov 10, 2017 10:53 pm

Hey everyone. I have been trying to get nodejs to work with my raspberry pi 3 kali linux setup. I successfully installed nodejs from the source and everything else seems to be working fine. Theres no candidate to install it from the package manager. Its installed, I have the paths here

Code: Select all

[email protected]:/usr/local/bin# whereis node  
node: /usr/bin/node /usr/sbin/node /sbin/node /usr/local/bin/node /opt/nodejs/bin/node

But its not recognized:

Code: Select all

[email protected]:/usr/local/bin# node 
bash: /usr/local/bin/node: No such file or directory

I need it as a dependency for beef-xss. I seem to be the only person in the world that is struggling with this problem. Does anybody have any ideas on what the problem is here? Any insight would be appreciated, thanks.

asandford
Posts: 1996
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: How to install Node.js on Raspberry Pi 3?

Sat Nov 11, 2017 1:22 am

joeybronzoni wrote:
Fri Nov 10, 2017 10:53 pm
Hey everyone. I have been trying to get nodejs to work with my raspberry pi 3 kali linux setup. I successfully installed nodejs from the source and everything else seems to be working fine. Theres no candidate to install it from the package manager. Its installed, I have the paths here

Code: Select all

[email protected]:/usr/local/bin# whereis node  
node: /usr/bin/node /usr/sbin/node /sbin/node /usr/local/bin/node /opt/nodejs/bin/node

But its not recognized:

Code: Select all

[email protected]:/usr/local/bin# node 
bash: /usr/local/bin/node: No such file or directory

I need it as a dependency for beef-xss. I seem to be the only person in the world that is struggling with this problem. Does anybody have any ideas on what the problem is here? Any insight would be appreciated, thanks.
Your search path is incorrect.

Code: Select all

export PATH=$PATH:/usr/bin/:/usr/sbin/:/sbin/:/usr/local/bin/:/opt/nodejs/bin/:
Will fix it, but you should have most of those in your PATH anyway

TheUnproPro
Posts: 1
Joined: Thu Dec 14, 2017 10:10 pm

Re: How to install Node.js on Raspberry Pi 3?

Thu Dec 14, 2017 10:13 pm

audstanley wrote:
Tue Dec 27, 2016 9:30 pm
This will work for EVERY raspberry pi (zero|1|2|3|zero-w)
And will install the latest version of node. It's always up to date.

Code: Select all

sudo wget -O - https://raw.githubusercontent.com/audstanley/NodeJs-Raspberry-Pi/master/Install-Node.sh | bash;
node -v;
source code here: https://github.com/audstanley/NodeJs-Raspberry-Pi

...and no it doesn't install Node v4.2.6 (post below). It installs the Latest version of Node.
I literally registered just to thank you.

LoopyD
Posts: 3
Joined: Thu Jun 07, 2018 6:10 pm

Re: How to install Node.js on Raspberry Pi 3?

Mon Jun 11, 2018 7:27 am

Please note that you will not be able to properly debug node.js applications if you do not have the aarch64 build of debain buster installed on the Raspberry PI 3 Model B (not B+) or the Fedora aarch64 release for Raspberry Pi.

You will receive the error in node when attaching the debugger, for IDEs like JetBrains that have these features, on debain stretch:

Code: Select all

Asyncronous stacktrace unsupported in 32 bit versions of node, debugger disabled.
To fix this, you'll need:

> A raspberry Pi 3 Model B (Not B+) that incorrectly reports itself as arm7l in Debain stretch (it runs in arm7l 32-bit mode, or armv8 64-bit mode, was recently brought to light mid-2018 after some research on the Cortex A53.
> an aarch64 supported OS, and an arm64 build of node.

The debain buster image:

https://github.com/Debian/raspi3-image-spec

SDCard image builds fine in Ubuntu 18.04 Bionic VM. (its a lot of work...)
> You will have to fix up the root account, setup sudo, a user, and fix bash....

Quick node install once you have a proper setup:

Code: Select all

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
Happy debugging !

audstanley
Posts: 9
Joined: Fri Nov 28, 2014 12:44 am

Re: How to install Node.js on Raspberry Pi 3?

Fri Jul 13, 2018 7:54 pm

ok, 2018 update:

Code: Select all

wget -O - https://raw.githubusercontent.com/audstanley/NodeJs-Raspberry-Pi/master/Install-Node.sh | sudo bash
node -v
Will not only install the latest version of node, but it will also track future npm global modules that you install. I've had to switch versions of node several times for different testing, and it can become a huge pain to not have the global modules that i use regularly when i switch versions. So rather than simply install node (whatever version). Install the node-install utility that comes with: https://github.com/audstanley/NodeJs-Raspberry-Pi

It might save you a lot of headache down the road... and there is "version selecting" that prompts you which comes in handy.
Read the docs, and you'll see the options.

Also, remember that friends don't let friends pipe to bash. So read the source code.

Return to “Beginners”