13

I download the last raspbian version (2016-05-27) on https://www.raspberrypi.org/downloads/raspbian/

Node.js is already installed with the 0.10.29 version, so I removed that and reinstalled it with

apt-get remove nodered
apt-get remove nodejs nodejs-legacy
curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -
sudo apt-get install -y build-essential python-rpi.gpio nodejs

But I would like my SD card to work on all Raspberry Pi models (Pi 1, 2, 3 and Zero) Currently, when I do a

node -v

on a Pi 1 or on a Pi zero, I get a "illegal instruction".

My question is: It is possible to install a copy of Node.js on a Pi that works on all models? Or is v0.10.29 the only one that works on all Pis?

Aurora0001
  • 6,357
  • 3
  • 25
  • 39
4Taine
  • 131
  • 1
  • 1
  • 3

5 Answers5

29

The reason why this is not working on your Raspberry Pi 1 is, that these packages are compiled for the wrong CPU - armhf (ARM 32-bit hard-float, ARMv7 and up: arm-linux-gnueabihf)

So the package should work on your Pi2 but not on the Pi1. I guess there is no quick and easy way to get an image that runs on both. If you want to install a modern nodejs on your Pi1, download the correct tarball from https://nodejs.org/dist/ For example:

cd ~
wget https://nodejs.org/dist/v6.2.1/node-v6.2.1-linux-armv6l.tar.gz
tar -xzf node-v6.2.1-linux-armv6l.tar.gz
node-v6.2.1-linux-armv6l/bin/node -v

The last command should print v6.2.1.

Now you can copy it to /usr/local

cd node-v6.2.1-linux-armv6l/
sudo cp -R * /usr/local/

For testing add /usr/local/bin to your path

export PATH=$PATH:/usr/local/bin
node -v
npm -v

This should print 6.2.1 and 3.9.3 for the versions of nodejs and npm. If you need a different version, just pick the one you like from the downloads.

Don't forget to add the PATH to your .bashrc to make it permanent.

To find the correct architecture, you can type cat /proc/cpuinfo in a terminal and that should show something like

pi@raspberrypi:~ $ cat /proc/cpuinfo
processor   : 0
model name  : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS    : 697.95
Features    : half thumb fastmult vfp edsp java tls 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xb76
CPU revision    : 7

update Just saw this answer https://raspberrypi.stackexchange.com/a/37976/34825 that basically does the same as I did, except install node in /opt/ and create symlinks in /usr/bin/.

Grmpfhmbl
  • 413
  • 4
  • 9
6

In one line of code, latest version, for any raspberry pi:

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

Source code: https://github.com/audstanley/NodeJs-Raspberry-Pi/

Grmpfhmbl
  • 413
  • 4
  • 9
Audstanley
  • 99
  • 1
  • 5
2

I liked Audstanley's solution above although it didn't work for me out of the box.

I found that I needed to run the script with root access.

This worked for me:

sudo bash
sudo wget -O - https://raw.githubusercontent.com/audstanley/NodeJs-Raspberry-Pi/master/Install-Node.sh | bash
exit
node -v
Darth Vader
  • 4,218
  • 24
  • 47
  • 70
1

I had the same issue and made some quick bash scripts for installing node v4, v5 and v6.3.1:

https://github.com/sdesalas/node-pi-zero

They are for the Pi Zero but should work for all ARMv6 compatible chips (1A 1B). In fact this should even work on the ARMv7 chips (2B 3B) as they are happy with the older binaries.

Hope you find them useful.

-1

Or get the latest version:

NODE="$(curl -sL https://nodejs.org/dist/latest | grep 'armv6l.tar.xz' | cut -d'"' -f2)"
wget https://nodejs.org/dist/latest/$NODE
Aurora0001
  • 6,357
  • 3
  • 25
  • 39
Pepe
  • 1