Installing newer version of NodeJS on Pi 3


25 posts
by ericp » Fri Mar 18, 2016 5:40 pm
How can I install a newer version of Node Js on the Raspberry Pi 3?
node version: v0.10.29
npm version: 1.4.21
I have Distributor ID: Raspbian Description: Raspbian GNU/Linux 8.0 (jessie) Release: 8.0 Codename: jessie
Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux


Thank you for any help.
Posts: 3
Joined: Fri Mar 18, 2016 5:35 pm
by LewisCowles1986 » Fri Mar 18, 2016 9:28 pm
Code: Select all
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout v5.9.0


Then whenever you want to use node run
Code: Select all
source ~/.nvm/nvm.sh


or add that line to your `.bashrc` or `.profile`
Posts: 3
Joined: Fri Mar 18, 2016 9:24 pm
by ericp » Fri Mar 18, 2016 11:23 pm
Thank you, but I still get "v0.10.29" when I run "node -v".
Am I missing something?
Posts: 3
Joined: Fri Mar 18, 2016 5:35 pm
by asandford » Sat Mar 19, 2016 12:03 am
ericp wrote:How can I install a newer version of Node Js on the Raspberry Pi 3?
node version: v0.10.29
npm version: 1.4.21
I have Distributor ID: Raspbian Description: Raspbian GNU/Linux 8.0 (jessie) Release: 8.0 Codename: jessie
Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux


Thank you for any help.

Code: Select all
pi@raspberrypi:~ $  node -v
v0.10.29
pi@raspberrypi:~ $  sudo su -
root@raspberrypi:~ # apt-get remove nodered -y
root@raspberrypi:~ # apt-get remove nodejs nodejs-legacy -y
root@raspberrypi:~ # apt-get remove npm  -y # if you installed npm
root@raspberrypi:~ # curl -sL https://deb.nodesource.com/setup_5.x | sudo bash -
root@raspberrypi:~# apt-get install nodejs -y
root@raspberrypi:~# node -v
v5.9.0
root@raspberrypi:~# npm -v
3.7.3
Posts: 1507
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing
by LewisCowles1986 » Sat Mar 19, 2016 12:47 am
ericp wrote:Thank you, but I still get "v0.10.29" when I run "node -v".
Am I missing something?


try running
Code: Select all
apt-get remove --purge node* npm*
Posts: 3
Joined: Fri Mar 18, 2016 9:24 pm
by LewisCowles1986 » Sat Mar 19, 2016 12:52 am
The reason to apt-get remove is because you may have a version installed via package manager. Otherwise I'd suggest reading the documentation on node version manager (nvm) as it might be you did not run the command exactly as it was typed. In any case you should be up and running soon ;)
Posts: 3
Joined: Fri Mar 18, 2016 9:24 pm
by ericp » Sun Mar 20, 2016 1:56 pm
asandford wrote:
Code: Select all
pi@raspberrypi:~ $  node -v
v0.10.29
pi@raspberrypi:~ $  sudo su -
root@raspberrypi:~ # apt-get remove nodered -y
root@raspberrypi:~ # apt-get remove nodejs nodejs-legacy -y
root@raspberrypi:~ # apt-get remove npm  -y # if you installed npm
root@raspberrypi:~ # curl -sL https://deb.nodesource.com/setup_5.x | sudo bash -
root@raspberrypi:~# apt-get install nodejs -y
root@raspberrypi:~# node -v
v5.9.0
root@raspberrypi:~# npm -v
3.7.3


Thank you asandford that worked for me.
Posts: 3
Joined: Fri Mar 18, 2016 5:35 pm
by surbyte » Thu May 05, 2016 6:49 pm
The right sequence for me

Code: Select all
pi@raspberrypi:~ $  node -v
v0.10.29
pi@raspberrypi:~ $  sudo su -
root@raspberrypi:~ # apt-get remove --purge node* npm*
root@raspberrypi:~ # curl -sL https://deb.nodesource.com/setup_5.x | sudo bash -
root@raspberrypi:~# apt-get install nodejs -y
root@raspberrypi:~# node -v
v5.11.0
root@raspberrypi:~# npm -v
3.8.6
Posts: 1
Joined: Fri Dec 25, 2015 3:47 pm
by KLL » Fri May 06, 2016 1:52 pm
i just install on my new RPI 3
Code: Select all
mkdir node
cd node
wget https://nodejs.org/dist/latest/node-v6.1.0-linux-armv7l.tar.gz
tar -xvf node-v6.1.0-linux-armv7l.tar.gz
cd node-v6.1.0-linux-armv7l
sudo cp -R * /usr/local/

sudo reboot
node -v
v6.1.0
npm -v
3.8.6


may i add here a question?
for MONGO i still do the
Code: Select all
wget https://github.com/tjanson/mongodb-armhf-deb/releases/download/v2.1.1-1/mongodb_2.1.1_armhf.deb
sudo dpkg -i mongodb_2.1.1_armhf.deb   //error
sudo apt-get -f install                // does the libboost thing
sudo dpkg -i mongodb_2.1.1_armhf.deb

( what gives a MongoDB shell version: 2.4.10 ) and then a
Code: Select all
wget http://andyfelong.com/downloads/core_mongodb.tar.gz
wget http://andyfelong.com/downloads/tools_mongodb.tar.gz
tar xvf core_mongodb.tar.gz
tar xvf tools_mongodb.tar.gz

sudo strip mongo*
sudo chown root:root mongo*
sudo chmod 755 mongo*
sudo service mongodb stop

sudo mv mongo* /usr/bin

what gives a MongoDB shell version: 3.0.9

anybody knows a better way / to a newer version???
Posts: 719
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
by audstanley » Tue Dec 27, 2016 9:08 pm
To Install Latest version of NodeJs 7.x:
Code: Select all
sudo apt-get install git && git clone https://github.com/audstanley/NodeJs-Raspberry-Pi-Arm7 && cd NodeJs-Raspberry-Pi-Arm7 && chmod +x Install-Node.sh && sudo ./Install-Node.sh;


This will also delete old versions of NodeJs, and you can re-run this to upgrade to the newest version of Node. This works an the Raspberry pi 2/3 running an ARM7. I'll update every integer version of Node, as they release new versions.
Posts: 7
Joined: Fri Nov 28, 2014 12:44 am
by Smartguy01 » Fri May 26, 2017 1:53 pm
This is awesome, thanks so much for sharing your script. This seemed to work fine for me - I have node v7.10.0 up and running properly.

Thanks again!
Posts: 1
Joined: Fri May 26, 2017 1:50 pm
by Heater » 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.

Get and install nvm:
Code: Select all
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

Use nvm to download and install the latest node.js version:
Code: Select all
nvm install node

Job done.

Except, read the instructions for nvm here: https://github.com/creationix/nvm/blob/ ... all-script

When you want to upgrade node to a newer version, or downgrade sometimes, nvm can do that very easily.
Posts: 7152
Joined: Tue Jul 17, 2012 3:02 pm
by KLL » Sat May 27, 2017 12:47 am
@Heater, is node-red still running?
Posts: 719
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
by Heater » Sat May 27, 2017 1:23 am
KLL,
...is node-red still running?

I'm not sure I understand your question. I never use node-red, neat though it is.

If you mean, "does installing node.js with nvm break node-red?" then I'm fairly confident it will not. nvm does not actually install anything to your "system", it puts everything in your user directory and arranges symlinks to the version of node you ask for.

I guessing though.
Posts: 7152
Joined: Tue Jul 17, 2012 3:02 pm
by KLL » Sat May 27, 2017 1:28 am
pls test and confirm, i read "best methods" already at a other post and then had to reinstall raspbian
Posts: 719
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
by Heater » Sat May 27, 2017 1:36 am
KLL,

Sorry, no can do, I'm travelling, no Pi to hand till I get home in a month or so..

If you have something that works then stick with it.

I'm not sure why you had to re-install raspbian just to get node.js and node-red working again. Removing and re-installing those packages should have done the trick.
Posts: 7152
Joined: Tue Jul 17, 2012 3:02 pm
by KLL » Sat May 27, 2017 1:51 am
i am ON THE ROAD too
https://goo.gl/maps/vTBQocVdcVv
will test at next system setup, thanks.
Posts: 719
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
by Heater » Sat May 27, 2017 8:47 am
Wow, looks much nicer than San Jose.
Posts: 7152
Joined: Tue Jul 17, 2012 3:02 pm
by KLL » Tue Jun 06, 2017 2:32 pm
ok, i checked, node red still running ( sorry i doubted you )

Code: Select all
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
? open new terminal?


pi@RPI0:~ $ nvm current
system
pi@RPI0:~ $ nvm --version
0.33.2
pi@RPI0:~ $ npm -v
bash: npm: command not found
pi@RPI0:~ $ node -v
v0.10.29



nvm install node


pi@RPI0:~ $ nvm --version
0.33.2
pi@RPI0:~ $ npm -v
5.0.0
pi@RPI0:~ $ node -v
v8.0.0

Posts: 719
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
by Heater » Tue Jun 06, 2017 3:03 pm
Great stuff.

I'd be inclined to remove that ancient node v0.10.29 just to avoid any confusion in the future.

$ sudo apt-get remove nodejs

Or what ever the Raspbian node.js packages is called.
Posts: 7152
Joined: Tue Jul 17, 2012 3:02 pm
by asandford » Wed Jun 07, 2017 12:09 am
Heater wrote:Great stuff.

I'd be inclined to remove that ancient node v0.10.29 just to avoid any confusion in the future.

$ sudo apt-get remove nodejs

Or what ever the Raspbian node.js packages is called.

I posted over a year ago:
Code: Select all
apt-get remove nodejs nodejs-legacy -y

It still might be relevant as the version of Node-Red that shipped then required it.

There is a script that will update nodejs, NR and npm (for NR):

Code: Select all
root@weatherpi:~# update-nodejs-and-nodered

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 any pre-installed versions of node.js and Node-RED
and replace them with node.js 6.x LTS (boron) and the latest Node-RED from Npm.
To do this it runs commands as root - please satisfy yourself that this will
not damage your Pi, or otherwise compromise your configuration.

Doing this may also be 'a bad thing' if you have installed lots of extra nodes.
Especially if they have any native binary component. Some nodes in your
~/.node-red directory will probably need to be re-installed afterwards, some
may need you to run npm update, and some may require you to run npm rebuild.

Are you really sure you want to do this ? (y/N) ? y
Running for user root at /root

This can take 20-30 minutes on a Pi 1 - please wait.

  Stop Node-RED                       ✔
  Remove old version of Node-RED      ✔
  Remove old version of node.js       -
  Update node.js LTS                  ✔   Node v6.10.3   Npm 3.10.10
  Clean npm cache                     ✔
  Install Node-RED core               ✔   0.16.2
  Install extra nodes                 ✔
  Install serialport node             ✔
  Npm rebuild existing nodes          ✔
  Add menu shortcut                   ✔
  Update systemd script               ✔
  Update update script                ✔

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



HTH
Posts: 1507
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing
by KLL » Wed Jun 07, 2017 1:49 am
asandford wrote:There is a script that will update nodejs, NR and npm (for NR):
Code: Select all
update-nodejs-and-nodered


thanks, also works perfect without sudo..

pi@RPI0:/ $ nodejs -v
v6.10.3
pi@RPI0:/ $ npm -v
3.10.10


see file:
Code: Select all
cat /usr/bin/update-nodejs-and-nodered
Posts: 719
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
by asandford » Wed Jun 07, 2017 2:19 am
KLL wrote:
thanks, also works perfect without sudo..

Old habit, Unix admin from 2000, I do everything as root.
Posts: 1507
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing
by Heater » Wed Jun 07, 2017 2:52 am
Why not just:

$ npm install -g node-red

or

$ npm install node-red

As intended?

Same for installing node-serial port and other modules.
Posts: 7152
Joined: Tue Jul 17, 2012 3:02 pm
by asandford » Wed Jun 07, 2017 11:50 pm
Heater wrote:Why not just:

$ npm install -g node-red

or

$ npm install node-red

As intended?

Same for installing node-serial port and other modules.

The devs at Node-Red suggest using the script they supplied to upgrade, so I guess that I am using what is intended to be used. Have a look here
To upgrade, run the following command as your normal user (typically pi):

update-nodejs-and-nodered

Note - If the serialport nodes do not appear when you restart, please re-run the update command. If the update command does not run or is not found then use the bash command from above.
Posts: 1507
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing