Delete and reinstall Node/NPM and Node Red WITHOUT removing current nodes, rPi

Hi all, thank you in advance for the assistance and please pardon the long post!

Could someone please detail, or refer me to, the process for removing and reinstalling Node, and Node Red? BUT, I don't want to lose the progress I've made and so I'm afraid to undo the progress I've made (esp after bricking my Pi last week!) I'm quite new to RaspPi, linux, node, and node red and have made strides but have hamstrung myself - by likely installing node twice (as both root and user). And, I'm unclear on the processes because there's conflicting info I find (which often is OS dependent it seems, or quite dated).

After "bricking" the Pi and starting over, I have a critical project coming on deadline, please help!

I tried this solution detailed here to copy my
My current situation with versions which I think indicate I've screwed up the installation...
....Bash history log attached
bash_history.pdf (26.3 KB)

pi@raspberrypi:~ $ which node-red

pi@raspberrypi:~ $ sudo which node-red

pi@raspberrypi:~ $ which node

pi@raspberrypi:~ $ sudo which node

pi@raspberrypi:~ $ node -v

pi@raspberrypi:~ $ sudo node -v

pi@raspberrypi:~ $ npm -v

pi@raspberrypi:~ $ sudo npm -v

pi@raspberrypi:~ $ which npm

pi@raspberrypi:~ $ sudo which npm

When trying to install some packages, I'm getting errors like:

pi@raspberrypi:~ $ sudo npm install i2c-bus

i2c-bus@5.2.1 install /home/pi/node_modules/i2c-bus
node-gyp rebuild

gyp WARN EACCES current user ("pi") does not have permission to access the dev dir "/root/.cache/node-gyp/10.22.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/node_modules/i2c-bus/.node-gyp"
make: Entering directory '/home/pi/node_modules/i2c-bus/build'
CXX(target) Release/
SOLINK_MODULE(target) Release/
COPY Release/i2c.node
make: Leaving directory '/home/pi/node_modules/i2c-bus/build'
npm WARN saveError ENOENT: no such file or directory, open '/home/pi/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/pi/package.json'
npm WARN pi No description
npm WARN pi No repository field.
npm WARN pi No README data
npm WARN pi No license field.

  • i2c-bus@5.2.1
    updated 1 package and audited 345 packages in 13.637s

-------------------------------------------------------------SECOND INSTANCE-----------------------------------------2020-10-11T16:40:50.830Z Install : node-red-contrib-easybotics-vl53l0x 0.0.3

2020-10-11T16:40:50.860Z npm install --no-audit --no-update-notifier --no-fund --save --save-prefix="~" --production node-red-contrib-easybotics-vl53l0x@0.0.3
2020-10-11T16:41:00.837Z [err] npm
2020-10-11T16:41:00.838Z [err] ERR! code ELOOP
2020-10-11T16:41:00.838Z [err] npm
2020-10-11T16:41:00.838Z [err] ERR! syscall open
2020-10-11T16:41:00.838Z [err] npm ERR!
2020-10-11T16:41:00.838Z [err] path /home/pi/.node-red/node_modules/serialport/npm-shrinkwrap.json
2020-10-11T16:41:00.839Z [err] npm
2020-10-11T16:41:00.839Z [err] ERR! errno -40
2020-10-11T16:41:00.842Z [err] npm
2020-10-11T16:41:00.842Z [err] ERR! ELOOP: too many symbolic links encountered, open '/home/pi/.node-red/node_modules/serialport/npm-shrinkwrap.json'
2020-10-11T16:41:00.860Z [err]
2020-10-11T16:41:00.861Z [err] npm ERR! A complete log of this run can be found in:
2020-10-11T16:41:00.861Z [err] npm
2020-10-11T16:41:00.861Z [err] ERR! /home/pi/.npm/_logs/2020-10-11T16_41_00_845Z-debug.log
2020-10-11T16:41:00.901Z rc=216

...this "too many symbolic links" error is preventing several packages from installing which seems connected to the missing files that are supposed to be there (see highlighted above) and has been part of every packages install (npm WARN enoent ENOENT: no such file or directory, open '/home/pi/package.json') - I assume this is an issue with the the conflicting versions, or placement (user v root)


  • Am I right in assuming this is a case of conflicting software?
  • Therefore, can I simply delete and reinstall node/npm and node red correctly?
    ** (defintely would rather install without NVM as I was trying to solve another issue when using nvm but I think that is causing more issues with the current node/pi setup)
  • If so, how can I preserve my currently installed node modules?
  • I would like to use the "official" nodered install package noted here - could I uninstall and then use this install package w/out conflicts?
    *Do I need to cd ~/pi/.node-red to run npm install [package]?

Currently referring to these links for ref but I lack confidence in parsing them for my situation:

^^but 2015! ...still relevant??

This is my pi (Raspberry Pi 4) info on boot:
pi@raspberrypi:~ $ dmesg
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 5.4.51-v7l+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1333 SMP Mon Aug 10 16:51:40 BST 2020
[ 0.000000] CPU: ARMv7 Processor [410fd083] revision 3 (ARMv7), cr=30c5383d

pi@raspberrypi:~ $ nvm ls
-> v14.5.0
default -> v14.5.0
node -> stable (-> v14.5.0) (default)
stable -> 14.5 (-> v14.5.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.22.1 (-> N/A)
lts/erbium -> v12.19.0 (-> N/A)


yes - all "your" nodes and flows should be in the ~/.node-red directory. - So as long as you don't delete that you should be ok... (Of course it would be best to back that up somewhere safe - but...) ...

Then yes - I would certainly remove nvm. Then go about removing nodejs . I would start with sudo apt purge nodejs - then got into /usr/local/bin and remove node and npm if still there - and then do likewise in /usr/bin. Then go into /etc/sources.list.d and remove nodesource.list if it exists...

Then check there is no node or npm still runnable - node -v and npm -v - then finally run the install script from that page... as normal user - (not sudo). Once that completes (successfully hopefully) then go into your ~/.node-red directory - and run npm rebuild (again no sudo).
If any fail then shout as they may removing and re-installing.

Note - you also should not use sudo to install extra nodes.

Thank you @dceejay

Seeing your name all over this forum inspires confidence so here goes:

  • sudo apt purge nodejs
    ..this returned the below errors (this is just a few of a longer list...):

dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/yargs/node_modules' not empty so not removed
dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/yargs/lib' not empty so not removed
dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/npm-registry-fetch' not empty so not removed
dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/npm-lifecycle' not empty so not removed
dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/npm-audit-report' not empty so not removed I tried to remove node and npm from usr/local/bin and get this:

npm: Unable to trash file /usr/local/bin/npm: Permission denied
node: Unable to trash file /usr/local/bin/node: Permission denied

...should try CLI to remove these files? or fix the first step first??

Thank you for assisting!

so yes we DO need to use sudo for this part :-)... be careful to copy these correctly

cd /usr/lib/node_modules
sudo rm -rf npm 
cd /usr/local/bin
sudo rm node npm
cd /usr/bin
sudo rm node npm
cd /etc/sources/list.d
sudo rm nodesource.list
cd ~

hopefully that should remove all trace of node and npm and get us ready to run the script

@dceejay THANK YOU for helping, it means so much when I'm this in the weeds! (sorry for the tardy reoky, HAD to break for fūd!)
So, the mystery continues, this is what happened:

  • pi@raspberrypi:~ $ cd /usr/lib/node_modules
  • pi@raspberrypi:/usr/lib/node_modules $ sudo rm -rf npm
  • pi@raspberrypi:/usr/lib/node_modules $ cd /usr/local/bin
  • pi@raspberrypi:/usr/local/bin $ sudo rm node npm
  • pi@raspberrypi:/usr/local/bin $ cd /usr/bin
  • pi@raspberrypi:/usr/bin $ sudo rm node npm
  • rm: cannot remove 'node': No such file or directory
  • rm: cannot remove 'npm': No such file or directory
  • pi@raspberrypi:/usr/bin $ cd /etc/sources/list.d
  • bash: cd: /etc/sources/list.d: No such file or directory

I looked in /etc/sources and also don't see that folder...

But, I do see that node and npm are no longer in ~/user/local/bin

QUESTION about NVM - I had used this to downgrade to Node v10 in an attempt to be successful at getting this node to install as I really need this to work in node-red. I had it working during my last setup but broke it all while trying to get my wireless connected (which still won't work, ugh), I did these steps, found here:

sudo nvm unalias default
sudo rm -Rf ~/.nvm
nvm unload
sudo rm -rf $NVM-DIR

...and now bash is no longer recognizing nvm so it looks like I'm done with nvm finally?!

Going to reboot and wait for more instruction :crossed_fingers:t3:

I believe I've successfully removed nvm, nodejs, and node-red (i.e. getting no hits from CTI and rm their dir where I've found them, partly based on your previously paths noted above). I've reinstalled using the node-red recommended nodejs+node-red bash installer, all seems well.

Next - do I need to use sudo when upgrading Nodejs since this packages only installs 12.x? I feel like this is where I went wrong last time - everything I see says sudo...

Nodejs 12 is the recommended LTS version. So leave it as is.

@dceejay Yessir, got it, I narrowly missed danger there (installing node 14)!

I have an issue related to the reinstall I just posted here if you have a moment to review and advise. Thank you for your contributions to this commmunity, I'm heartened after lots of learning.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.