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

**URL:** <https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201>\
**Category:** General\
**Created:** [13 October 2020 20:55 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201 "2020-10-13T20:55:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![danieldean1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danieldean1/32/29198_2.png) [@danieldean1](https://discourse.nodered.org/u/danieldean1)\
**Post date:** [13 October 2020 20:55 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/1 "2020-10-13T20:55:27Z")

</div>

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](https://discourse.nodered.org/uploads/short-url/cL1Isvx6ZyYMOpAwH0TYRCNLQ8T.pdf) (26.3 KB)

pi@raspberrypi:~ $ which node-red  
/usr/bin/node-red

pi@raspberrypi:~ $ sudo which node-red  
/usr/bin/node-red

pi@raspberrypi:~ $ which node  
/home/pi/.config/nvm/versions/node/v14.5.0/bin/node

pi@raspberrypi:~ $ sudo which node  
/usr/local/bin/node

pi@raspberrypi:~ $ node -v  
v14.5.0

pi@raspberrypi:~ $ sudo node -v  
v14.5.0

pi@raspberrypi:~ $ npm -v  
6.14.5

pi@raspberrypi:~ $ sudo npm -v  
6.14.5

pi@raspberrypi:~ $ which npm  
/home/pi/.config/nvm/versions/node/v14.5.0/bin/npm

pi@raspberrypi:~ $ sudo which npm  
/usr/local/bin/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/obj.target/i2c/src/i2c.o  
SOLINK\_MODULE(target) Release/obj.target/i2c.node  
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

* * *

AND  
-------------------------------------------------------------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)

**QUESTIONS:**

- 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](https://nodered.org/docs/getting-started/raspberrypi) - 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:**

> [@Node-red-start not working but node-red working](https://discourse.nodered.org/t/node-red-start-not-working-but-node-red-working/14618/7):
>
> Hmmm a pi start script specific problem I guess... I am able to use an nvm based setup just fine on my development system.

> **[Supported Node versions : Node-RED](https://nodered.org/docs/faq/node-versions#using-nvm)**

> <https://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x>

^^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  
...  
and:

pi@raspberrypi:~ $ nvm ls  
-\> v14.5.0  
system  
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)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 October 2020 21:14 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/2 "2020-10-13T21:14:29Z")

</div>

Hi,

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.

---

<div class="post-metadata">

**Author:** ![danieldean1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danieldean1/32/29198_2.png) [@danieldean1](https://discourse.nodered.org/u/danieldean1)\
**Post date:** [13 October 2020 21:48 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/3 "2020-10-13T21:48:08Z")

</div>

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

...so 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!

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 October 2020 22:20 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/4 "2020-10-13T22:20:34Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![danieldean1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danieldean1/32/29198_2.png) [@danieldean1](https://discourse.nodered.org/u/danieldean1)\
**Post date:** [13 October 2020 23:49 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/5 "2020-10-13T23:49:44Z")

</div>

@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](https://flows.nodered.org/node/node-red-contrib-easybotics-vl53l0x)** 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)...so, I did these steps, found [here](https://stackoverflow.com/questions/47240567/uninstalling-the-currently-active-version-of-node-js-with-nvm):

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 🤞🏼

---

<div class="post-metadata">

**Author:** ![danieldean1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danieldean1/32/29198_2.png) [@danieldean1](https://discourse.nodered.org/u/danieldean1)\
**Post date:** [14 October 2020 05:46 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/7 "2020-10-14T05:46:33Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 October 2020 06:37 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/8 "2020-10-14T06:37:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danieldean1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danieldean1/32/29198_2.png) [@danieldean1](https://discourse.nodered.org/u/danieldean1)\
**Post date:** [14 October 2020 12:55 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/9 "2020-10-14T12:55:20Z")

</div>

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

I have an issue related to the reinstall I just posted [here](https://discourse.nodered.org/t/moving-node-red-project-to-new-install-missing-credential/34225) if you have a moment to review and advise. Thank you for your contributions to this commmunity, I'm heartened after lots of learning.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 December 2020 12:55 UTC](https://discourse.nodered.org/t/delete-and-reinstall-node-npm-and-node-red-without-removing-current-nodes-rpi/34201/10 "2020-12-13T12:55:25Z")

</div>

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