12

Setup

I have a PI3 with Jessie. According to Wikipedia it uses a ARM Cortex-A53 which is ARMv8-A.

When installing node.js using this adafruit tutorial I end up with node v0.12 which is still beta stage.

Question:

I would like to use at least v4 of node.js. How do I install this and get it running?

Failed Approaches

First

This tutorial describes how to do it.

wget https://nodejs.org/dist/v5.0.0/node-v5.0.0-linux-arm64.tar.gz
tar -xvf node-v5.0.0-linux-arm64.tar.gz
cd node-v5.0.0-linux-arm64
sudo cp -R * /usr/local/ #attention copies also readme and other not required files

From v.4.0.0 Our test suite must be continually passing on ARMv6, ARMv7 and the new 64-bit ARMv8 processors.

V.5.0.0: ARMv8 64-bit Binary:

=> It is not able to execute the binary. -bash: /usr/local/bin/node: cannot execute binary file: Exec format error

Second

https://github.com/nodesource/distributions#installation-instructions

Stops during sudo apt-get install -y nodejs

But I think they not yet have support for arm64 Github issue

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gyp libc-ares-dev libc-ares2 libjs-node-uuid libjs-underscore libssl-dev
  libssl-doc libv8-3.14-dev libv8-3.14.5 node-abbrev node-ansi
  node-ansi-color-table node-archy node-async node-block-stream
  node-combined-stream node-cookie-jar node-delayed-stream node-forever-agent
  node-form-data node-fstream node-fstream-ignore node-github-url-from-git
  node-glob node-graceful-fs node-gyp node-inherits node-ini
  node-json-stringify-safe node-lockfile node-lru-cache node-mime
  node-minimatch node-mkdirp node-mute-stream node-node-uuid node-nopt
  node-normalize-package-data node-npmlog node-once node-osenv node-qs
  node-read node-read-package-json node-request node-retry node-rimraf
  node-semver node-sha node-sigmund node-slide node-tar node-tunnel-agent
  node-underscore node-which
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
1 not fully installed or removed.
Need to get 0 B/8,028 kB of archives.
After this operation, 38.3 MB of additional disk space will be used.
Selecting previously unselected package nodejs.
(Reading database ... 125270 files and directories currently installed.)
Preparing to unpack .../nodejs_5.10.0-1nodesource1~jessie1_armhf.deb ...
Detected old npm client, removing...
Unpacking nodejs (5.10.0-1nodesource1~jessie1) ...

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  294.455070] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  295.546888] Process mmcqd/0 (pid: 52, stack limit = 0xb8cde210)

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  295.618619] Stack: (0xb8cdfd88 to 0xb8ce0000)

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  295.671359] fd80:                   00000007 b9687680 b8cdfdc4 b8cdfda0 8043c924 8043cb34

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  295.770515] fda0: b8cdfdc4 b8cdfdb0 8055fb5c b8cf0150 b9687400 b9687680 b8cdfdfc b8cdfdc8

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  295.869667] fdc0: 8043d588 8043c738 b9687624 80441c80 b8cdfdfc b8cdfde0 80441c80 b8cf0150

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  295.968821] fde0: b9687400 b8cf0258 b8cf0150 b8cdfea4 b8cdfe14 b8cdfe00 80424c54 8043d428

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.067976] fe00: b9687400 00000000 b8cdfe64 b8cdfe18 80425980 80424b5c 00000001 b8cf0034

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.167140] fe20: adec51d0 00000000 b8cb8600 8005f4f8 b8cdfe30 b8cdfe30 b8cdfe5c adec51d0

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.266294] fe40: b8cf0008 b8cf014c b9687c00 b8cf0150 00000000 adec51d0 b8cdfed4 b8cdfe68

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.365448] fe60: 80434494 804256e0 adec51d0 adec5220 b8cdfe94 b8cdfe80 802c88a0 802f97d4

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.464600] fe80: b971e580 b971e584 b8cdfeb4 00000000 b8cf0000 00000000 00000000 80443bec

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.563754] fea0: ffffffff 00ffffff b8cdfed4 b8cf0008 b9687c00 adec51d0 b8cf0000 b8cf0000

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.662907] fec0: 00000001 24590411 b8cdff24 b8cdfed8 80434fd8 804343dc 00000000 adec51d0

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.762059] fee0: b8cf8000 b8cde000 b8cdff0c b8cdfef8 802cf320 b9687400 b8cf0008 b8cf0008

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.861214] ff00: b8cf8000 b8cde000 00000000 24590411 00000001 adec51d0 b8cdff5c b8cdff28

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  296.960367] ff20: 804367c8 80434ee0 80436708 b8cf0010 00000000 b97151c0 00000000 b8cf0008

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  297.059522] ff40: 80436708 00000000 00000000 00000000 b8cdffac b8cdff60 80042494 80436714

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  297.158687] ff60: 8055fba4 00000000 b8cdff94 b8cf0008 00000000 00000000 b8cdff78 b8cdff78

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  297.257840] ff80: 00000000 00000000 b8cdff88 b8cdff88 b97151c0 800423ac 00000000 00000000

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  297.356994] ffa0: 00000000 b8cdffb0 8000f9f8 800423b8 00000000 00000000 00000000 00000000

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  297.456177] ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  297.555354] ffe0: 00000000 00000000 00000000 00000000 00000013 00000000 55550000 55554000

Message from syslogd@raspberrypi at Apr  6 09:47:46 ...
 kernel:[  298.607208] Code: e89da818 e28400fc ebf11884 eafffff6 (e7f001f2)

Related Topics

How to install node.js with GPIO

Andi Giga
  • 543
  • 1
  • 7
  • 17
  • As of today, the RPi3 latest Raspbian (Stretch) is still not supplied with native support for the armv8. – not2qubit Jan 09 '18 at 14:25

4 Answers4

11

I installed node.js using the second method in the question today, worked just fine. I have Raspbian Jessie on a Raspberry 3.

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

I don't know why that method didn't work for you. Perhaps it's been updated and works better now?

oldwizard
  • 226
  • 1
  • 5
4

How to install

wget https://nodejs.org/dist/v5.0.0/node-v5.0.0-linux-armv7l.tar.gz
tar -xvf node-v5.0.0-linux-armv7l.tar.gz
cd node-v5.0.0-linux-armv7l
sudo cp -R * /usr/local/ #attention copies also readme and other not required files

Why ArmV7:

On my pi & package is written Raspberry Pi 3 Model B and according to wikipedia: The ARM Cortex-A53 is a microarchitecture implementing the ARMv8-A 64-bit which leaded me to download the ARMv8 64-bit Binary.

But the pi shows with uname -a Linux raspberrypi 4.1.14-v7+ #4 SMP PREEMPT Wed Mar 23 15:30:13 UTC 2016 armv7l GNU/Linux. So apparently there is a armv7 in the pi.

EDIT: It seems to be correct https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=140572

The 32 bit mode is used, because of the missing support of the operating system, from my understanding. If somebody can explain this more precisely, please leave a comment.

Andi Giga
  • 543
  • 1
  • 7
  • 17
  • Debian has an arm64 Version here (https://www.debian.org/CD/netinst/) but I haven't been able to boot that one yet. – ott-- Apr 29 '16 at 18:23
3

Using nvm

An alternative solution is using nvm as the installer for Node. nvm stands for Node Version Manager and it has many benefits like:

  • picking the right version for your platform,
  • easily update Node with a simple command,
  • different node versions installed at the same time (to check your program with different versions of node to test deployment to different setups, for example)

While I was skeptical at the beginning (although I use nvm successfully on other systems), after looking for the best solution to have node and npm installed and accessible for all users (including root, which is required to access hardware on RasPi) and diving into all node distributions, packages and sources, I decided to give this method a try. And it worked!


Here are my steps:

  1. first of all, you need to install nvm. You may run this script from your home folder or anywhere else but it will install nvm for the current user (pi in my case although I had another one created for this purpose which is now unnecessary). You may want to replace the version (v0.32.0) with the latest one.

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

    You need to reopen the terminal to grab access to nvm

  2. then you install Node with this simple command:

    nvm install v6.6.0

    You may want to check the available versions by issuing nvm ls-remote and pick the one that suits you

  3. you set this version as the default node for your system:

    nvm alias default v6.6.0

  4. and check the installed version with node -v and npm -v


Now you have Node v6.6.0 installed for the current user. It is not yet available to root or other users on your system but you might want that so you can either:

  • create symlinks (aliases) to make it available system-wide:

    sudo ln -s /home/pi/.nvm/versions/node/v6.6.0/bin/node /usr/bin/node

    sudo ln -s /home/pi/.nvm/versions/node/v6.6.0/bin/npm /usr/bin/npm

  • Or, in case your system already has node installed by default and you get an error with the above method (like in my case) run this awkward line:

    n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

and your freshly installed node is now available to everyone allowing you to install npm packages globally, etc.

Please note that whenever you want to switch the node version you will have to run the above command (which may seem scary but all it does is to copy the node files to /usr/local, it is written in a condensed form).

I hope this helps someone and saves some time!


References:

HOW TO INSTALL NODE.JS ON RASPBERRY PI by Brandon Cannaday,

the 1st comment from the above post (by RYAN PARSLEY),

this StackOverflow answer,

the DigitalOcean tutorial that came with the /usr/local copy idea,

and the Internet and Google which allowed me to spend hours trying to pick the best solution from an ocean of ideas :)

bosch
  • 131
  • 2
1

According to this post, and also in my own experience, all Raspbian pre-installed node.js versions are outdated. Your best option is therefore to first remove all previous node installations and re-install it. This also worked great for Raspbian Stretch.

Do this:

# Remove outdated Debian package (`node -v` ==> v4.8.2)
sudo apt-get remove nodejs nodejs-legacy nodered
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs

Now the versions are: nodejs: v9.3.0 npm: v5.5.1 --> npm need update

sudo npm install npm@latest -g

Then install these useful tools:

sudo npm install -g node-gyp sudo npm install -g npm-check sudo npm install -g npm-check-updates

If needed, you can re-install node-red with:

sudo npm install -g --unsafe-perm node-red


WARNING

Some idiot posted an sudo apt-get remove node*, which destroyed the OS. Do not use wildcards with apt-get remove/purge, since it was not designed to handle wildcards. (It's pure luck when they do work!)


UPDATE 2021-05-04

It seem that today the preferred curl command is:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
not2qubit
  • 1,407
  • 2
  • 14
  • 23