User avatar
E3V3A
Posts: 13
Joined: Sun Apr 17, 2016 7:13 am
Location: -∇φ

Re: Installing newer version of NodeJS on Pi 3

Mon Jan 08, 2018 7:03 pm

All nodejs related out-of-the-box software on the RaspberryPi3 are usually outdated. The recovery from this old junk is rather cumbersome if you are not used to dealing with these issues. I recently made a fresh Stretch install and managed to get all node stuff into top shape by fist removing all dated nodejs junk by doing the following:

Code: Select all

# Remove outdated ( 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

# nvers ==> nodejs: v9.3.0   npm: v5.5.1 --> need update
sudo npm install npm@latest -g
In addition, it's highly recommended to also install these node tools.

Code: Select all

sudo npm install -g node-gyp
sudo npm install -g npm-check
sudo npm install -g npm-check-updates
Then re-install node-red again with:

Code: Select all

sudo npm install -g --unsafe-perm node-red
Feel free to try to leave out the "--unsafe-perm" option.
Also, notice how we removed the Debian dpkg package but used npm to reinstall it!

Heater
Posts: 8630
Joined: Tue Jul 17, 2012 3:02 pm

Re: Installing newer version of NodeJS on Pi 3

Mon Jan 08, 2018 7:17 pm

My prefered method of installing node.js is to use the Node Version Manager, nvm.

Code: Select all

$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

$ nvm install node
The first step only needs to be done once. The second step will install the latest node.js (Or perhaps latest LTS release, I forget)

After that you can install newer versions of node as they come along with nvm. Or you can revert to older versions if something ever breaks in a new one.

nvm has lots of nice features you can read about here:
https://github.com/creationix/nvm

There is no need to uninstall the version of node installed by Raspbian. You can even use nvm to switch to using it if you really want to.

Sorry, I have no idea about node-red. It's neat but I never found a use for it.

asandford
Posts: 1862
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Installing newer version of NodeJS on Pi 3

Tue Jan 09, 2018 12:14 am

All that 'junk' was the reason that node.js was wrapped into the image, it was only included for node-red, so be thankful for it.

The "-g --unsafe-perm" option is pretty much required otherwise it gets messy.

Also bear i mind which versions of nodejs work with Node-red; it's not bleeding edge by any means.

Heater
Posts: 8630
Joined: Tue Jul 17, 2012 3:02 pm

Re: Installing newer version of NodeJS on Pi 3

Tue Jan 09, 2018 11:19 am

I'm not particularly keen on the OP's suggestion because it adds a 'foreign' repo to the apt sources list and requires root privileges to run the installer. That has security consequences.

I think putting node.js in the Raspbian packages was a mistake. It has always been far behind the latest developments of node. Node has been moving forward very rapidly.

Even worse is putting all those node.js packages into deb packages. Again, they are always massively out of date but the main point is that node.js comes with a very good package manager, npm, which is the proper way of dealing with node modules and their version management in a node project.

I have not tried node-red for a long time but as far as I can tell it works with the latest node versions. If it does not, that is not a problem, nvm easily installs any required old node.js version.

prodata
Posts: 141
Joined: Tue Jan 24, 2012 5:53 pm
Contact: Website

Re: Installing newer version of NodeJS on Pi 3

Sat Jan 13, 2018 9:33 pm

Looking to use Node Red, it looks like I made a mistake in trying the update-nodejs-and-nodered script. This is on a Pi 3 attached to a recent Pi-Top laptop (which is going to be returned because of what appears to be a design fault with the USB connector, but that's another story) and running the SD card supplied with the Pi-Top. Other than some hardware-specific tweaks I think this gives the latest OS version, whatever that might be.

The first time I ran the script, it seemed to complete OK, but then reported that (IIRC) the NR installation was incomplete and to re-run the same script. On doing this, it stopped at:

Code: Select all

Node.js LTS Failed to install Node.js: Exit
which is all a bit curious, given that it didn't baulk at this step first time around, though I don't recall seeing the LTS suffix the first time BICBW.

Anyone able to offer any advice as to how best to recover from here please? This is a Pi that was previously running NR OK, but in starting a new project I wanted to check that my NR version was as up to date as possible. Sorry, but I'm not an experienced Linux user - my whole interest is focused on using NR so would appreciate the simplest solution to recovering a working (but hopefully updated) NR installation

Heater
Posts: 8630
Joined: Tue Jul 17, 2012 3:02 pm

Re: Installing newer version of NodeJS on Pi 3

Sat Jan 13, 2018 11:50 pm

Is that the only message it put out? I'm willing to bet there are some clues in whatever came before that.

Personally I would try forgetting all that install node red the proper way.

Firstly install node.js using nvm as I described above.

Then install node-red as described here: https://www.npmjs.com/package/node-red
and here: https://github.com/node-red/node-red

$ sudo npm install -g node-red
$ node-red

Then open http://localhost:1880

prodata
Posts: 141
Joined: Tue Jan 24, 2012 5:53 pm
Contact: Website

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 11:51 am

Thanks, but for installing nvm, if you mean:

Code: Select all

$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

$ nvm install node
Then that doesn't seem to install nvm on my Pi. (I'm guessing the wget argument after the 'q' is the letter O and not the digit 0 - the zero gives an error anyway). The command seems to get accepted with no obvious errors, but trying to call up nvm thereafter just gives an nvm: command not found error.

Any ideas where I'm going wrong please?

mattmiller
Posts: 1713
Joined: Thu Feb 05, 2015 11:25 pm

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 12:15 pm

I think that is slight typo
last time heater suggested how to install it they said use

Code: Select all

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

prodata
Posts: 141
Joined: Tue Jan 24, 2012 5:53 pm
Contact: Website

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 12:28 pm

Thanks, and yes as it happens I had started to go down the curl route after checking the github page. Still got NR to download but nvm now seems to have installed OK as is node (after a terminal close and reopen that I had to do).

Heater
Posts: 8630
Joined: Tue Jul 17, 2012 3:02 pm

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 1:07 pm

Use curl or wget. The examples shown have been correct.

Sorry, I always forget to mention that need to exit and restart the shell.

Or I think you can just do this to set the path to nvm:

$ source ~/.profile

prodata
Posts: 141
Joined: Tue Jan 24, 2012 5:53 pm
Contact: Website

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 1:20 pm

Heater wrote:
Sun Jan 14, 2018 1:07 pm
Use curl or wget. The examples shown have been correct.
Just to be clear, all I can say is that on my particular Pi installation, wget failed but curl worked OK. (And I tried 2 or 3 times with wget, carefully checking the syntax each time, but with no success.)

Heater
Posts: 8630
Joined: Tue Jul 17, 2012 3:02 pm

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 4:28 pm

Very odd. I have used both many times on Pi and PC and elsewhere.

What are the error messages on failure?

prodata
Posts: 141
Joined: Tue Jan 24, 2012 5:53 pm
Contact: Website

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 4:48 pm

There were no error messages on the terminal, just a shortish pause while wget appeared to be doing something, but then simply popped up the command prompt again. Maybe there's a log message, but must admit I haven't checked.

TBH I'm starting to wonder if this isn't something to do with the Pi-Top flavour of Jessie (I think it is) that the Pi is currently running. Some other oddities are starting to appear, like node has been installed but not, apparently, npm, which I thought always co-installed with node these days.

I'm getting to the point where the Pi-Top is going to be returned for other reasons and so I might just start over with default Pi install. All a bit of a nuisance, but hmm.

Heater
Posts: 8630
Joined: Tue Jul 17, 2012 3:02 pm

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 4:53 pm

I have no idea about whatever OS the Pi-top uses. But if it is based on Debian/Raspbian then as far as I can tell it is normal not to get npm with a node.js install. Which is really weird and stupid but there we are. At least that was the case last time I checked.

User avatar
scruss
Posts: 1506
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 7:00 pm

Heater wrote:
Fri May 26, 2017 11:07 pm
The best way I have found to install node.js is to use the Node Version Manager, nvm, as mentioned above.
Seems kind of a long way around compared to the official method, Debian and Ubuntu based Linux distributions

Code: Select all

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential
Alternatively, for Node.js 9:

Code: Select all

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential
Only works for a Raspberry Pi 2 or 3, though.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Heater
Posts: 8630
Joined: Tue Jul 17, 2012 3:02 pm

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 8:13 pm

"Long way around" ?

In terms of the commands you have to type it seems much the same to me.

The nvm method has some advantages:

1) It does not replace your operating systems idea of node. Should you or some other package ever need that.

2) It makes it very easy to install new node versions as they come. Or older versions if you need. Or hop between them if something breaks as node is developed.

3) All versions installed with nvm are available, although not normally on you path, so a stable setup can continue to run whilst you experiment with a new node versions.

4) It does not add any foreign repos to you operating systems package sources.

Take you pick!

asandford
Posts: 1862
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Installing newer version of NodeJS on Pi 3

Sun Jan 14, 2018 10:59 pm

Heater wrote:
Sat Jan 13, 2018 11:50 pm
Is that the only message it put out? I'm willing to bet there are some clues in whatever came before that.

Personally I would try forgetting all that install node red the proper way.
That is the proper way to upgrade node-red, with other goals, according to the developers
The intention of the script is to…

upgrade an existing user to LTS 6.x or 8.x Node.js and latest Node-RED
migrate any existing globally installed nodes into the users ~/.node-red space so they can be managed via the palette manager
optionally (re)install the extra nodes that are pre-installed on a full Raspbian Pi image
FWIW, here is the output:

Code: Select all

root@raspberrypi:~# update-nodejs-and-nodered

Fetching Node-RED update.

Root user detected. Typically install as a normal user. No need for sudo.

Are you really sure you want to install as root ? (y/N) ? y


This script will remove versions of Node.js prior to version 6.x of Node.js and Node-RED
and if necessary replace them with Node.js 8.x LTS (carbon) and the latest Node-RED from Npm.

It also moves any Node-RED nodes that are globally installed into your user
~/.node-red/node_modules directory, and adds them to your package.json, so that
you can manage them with the palette manager.

It also tries to run 'npm rebuild' to refresh any extra nodes you have installed
that may have a native binary component. While this normally works ok, you need
to check that it succeeds for your combination of installed nodes.

To do all this it runs commands as root - please satisfy yourself that this will
not damage your Pi, or otherwise compromise your configuration.
If in doubt please backup your SD card first.

Are you really sure you want to do this ? [y/N] ?y

Running Node-RED update for user root at /root

This can take 20-30 minutes on the slower Pi versions - please wait.

  Stop Node-RED                       ✔
  Remove old version of Node-RED      ✔
  Remove old version of Node.js       -
  Update Node.js LTS                  ✔   Node v8.9.4   Npm 5.6.0
  Clean npm cache                     ✔
  Install Node-RED core               ✔   0.17.5
  Move global nodes to local          ✔
  Install extra Pi nodes              -
  Npm rebuild existing nodes          ✔
  Add menu shortcut                   ✔
  Update systemd script               ✔
  Update update script                ✔

Any errors will be logged to   /var/log/nodered-install.log

All done.
  You can now start Node-RED with the command  node-red-start
  or using the icon under   Menu / Programming / Node-RED
  Then point your browser to localhost:1880 or http://{your_pi_ip-address}:1880

Started  Sun 14 Jan 22:54:04 UTC 2018  -  Finished  Sun 14 Jan 22:57:00 UTC 2018

root@raspberrypi:~#

Heater
Posts: 8630
Joined: Tue Jul 17, 2012 3:02 pm

Re: Installing newer version of NodeJS on Pi 3

Mon Jan 15, 2018 4:05 am

I guess the node-red developers are very confused then. Because that is not what it says here:

https://www.npmjs.com/package/node-red

Or here:

https://github.com/node-red/node-red

asandford
Posts: 1862
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Installing newer version of NodeJS on Pi 3

Mon Jan 15, 2018 10:46 pm

Heater wrote:
Mon Jan 15, 2018 4:05 am
I guess the node-red developers are very confused then. Because that is not what it says here:

https://www.npmjs.com/package/node-red

Or here:

https://github.com/node-red/node-red
I was just quoting what was said here, which is a page dedicated to the Pi.

The generic upgrade instructions are here

Return to “Other languages”

Who is online

Users browsing this forum: No registered users and 10 guests