# Pi install nodejs question

**URL:** <https://discourse.nodered.org/t/pi-install-nodejs-question/8800>\
**Category:** General\
**Created:** [10 March 2019 10:51 UTC](https://discourse.nodered.org/t/pi-install-nodejs-question/8800 "2019-03-10T10:51:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 March 2019 10:51 UTC](https://discourse.nodered.org/t/pi-install-nodejs-question/8800/1 "2019-03-10T10:51:10Z")

</div>

I have just run the `bash <(curl...` script to install node-red on a pi-zero running raspbian lite. It is all working ok but I am confused by something.  
The first time round I got stuck in the `node-Red not fully installed` loop wanting to run re-run the script so I removed `/usr/lib/node_modules` and `usr/bin/node`, checked that `node -v` showed command not found and re-ran the script, and all seems to be working ok. However I am confused about how nodejs has been installed. I see

```auto
$ node -v
v10.15.3
$ npm -v
6.9.0
$ which node
/usr/bin/node
$ which npm
/usr/bin/npm

```

which looks fine, but I also see

```auto
$ apt-cache policy nodejs
nodejs:
  Installed: (none)
  Candidate: 8.11.1~dfsg-2~bpo9+1
  Version table:
     8.11.1~dfsg-2~bpo9+1 500
        500 http://archive.raspberrypi.org/debian stretch/main armhf Packages
     4.8.2~dfsg-1 500
        500 http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages

```

and there is no nodesource repo in `/etc/apt/sources.list.d` so I don't understand how node has been installed.

During the script it showed

```bash
  Stop Node-RED ✔
  Remove old version of Node-RED ✔
  Remove old version of Node.js ✔
  Install Node.js for Armv6 ✔ Node v10.15.3 Npm 6.9.0
  Clean npm cache ✔
  Install Node-RED core ✔ 0.19.6 
  Move global nodes to local -
  Install extra Pi nodes -
  Npm rebuild existing nodes -
  Add shortcut commands ✔
  Update systemd script ✔

```

The relevant section of the install log has

```bash
Package 'nodejs-legacy' is not installed, so not removed
Package 'npm' is not installed, so not removed
Package 'nodejs' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
dpkg: warning: ignoring request to remove nodejs which isn't installed
dpkg: warning: ignoring request to remove node which isn't installed
Reading package lists...
Building dependency tree...
Reading state information...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
/usr/bin/npx -> /usr/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.9.0
added 54 packages from 9 contributors, removed 15 packages and updated 47 packages in 372.011s

```

So the question is, how has nodejs been installed?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 March 2019 14:04 UTC](https://discourse.nodered.org/t/pi-install-nodejs-question/8800/2 "2019-03-10T14:04:49Z")

</div>

See:

> **[node-red/raspbian-deb-package](https://github.com/node-red/raspbian-deb-package)**
>
> Scripts required to build the Node-RED deb package for Raspbian - node-red/raspbian-deb-package

The relevant lines are currently 28 & 29

> <https://github.com/node-red/raspbian-deb-package/blob/master/node-red-pi-install.sh#L28-L29>

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 March 2019 14:23 UTC](https://discourse.nodered.org/t/pi-install-nodejs-question/8800/3 "2019-03-10T14:23:36Z")

</div>

Sorry, I am missing something. How does that relate to the fact that `apt-cache policy nodejs` says it is not installed, and in the pi install script I see

```auto
if curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - 2>&1 | sudo tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi

```

which I thought was adding the nodesource repository so nodejs could be installed from there.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 March 2019 15:58 UTC](https://discourse.nodered.org/t/pi-install-nodejs-question/8800/4 "2019-03-10T15:58:09Z")

</div>

> [@Colin](#):
>
> How does that relate

I've never used the `apt-cache policy nodejs` command and I don't know what it does. As I don't use Dave's excellent script, my Pi's look different:

```auto
pi@pi3:~/nrlive $ apt-cache policy nodejs
nodejs:
  Installed: 8.15.1-1nodesource1
  Candidate: 8.15.1-1nodesource1
  Version table:
 *** 8.15.1-1nodesource1 500
        500 https://deb.nodesource.com/node_8.x stretch/main armhf Packages
        100 /var/lib/dpkg/status
     8.11.1~dfsg-2~bpo9+1 100
        100 http://ftp.debian.org/debian stretch-backports/main armhf Packages
     8.11.1~dfsg-2~bpo9+1 500
        500 http://archive.raspberrypi.org/debian stretch/main armhf Packages
     4.8.2~dfsg-1 500
        500 http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages

```

As you can see, I install direct from the nodesource library. Which, as you say, Dave's script is also doing.

---

<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:** [10 March 2019 16:07 UTC](https://discourse.nodered.org/t/pi-install-nodejs-question/8800/5 "2019-03-10T16:07:51Z")

</div>

the magic words in the OP are "on a pi-zero"...  
the Pi0 is an Arm6 device which the nodesource guys don't support ( see [https://github.com/nodesource/distributions#deb](https://github.com/nodesource/distributions#deb)) so the magic is here instead - [https://github.com/node-red/raspbian-deb-package/blob/master/resources/update-nodejs-and-nodered#L183](https://github.com/node-red/raspbian-deb-package/blob/master/resources/update-nodejs-and-nodered#L183) - ie I get the version direct from [nodejs.org](http://nodejs.org) and just unpack it.

Also as This method does NOT use apt - then the apt-cache will say a) that it's isn't installed and b) that the version available is 8.11 (or whatever)... This is an ongoing issue with Debian and one of the reasons the pre-built Pi package is recommended to be updated as soon as you can 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 March 2019 16:29 UTC](https://discourse.nodered.org/t/pi-install-nodejs-question/8800/6 "2019-03-10T16:29:52Z")

</div>

> [@dceejay](#):
>
> the magic words in the OP are "on a pi-zero"

Ah, ok, thanks.

I don't think you are right about not using apt on a non-zero pi. Having fetched the nodesource repo the script uses apt to install from there, so on a pi 3 it shows something like

```bash
$ apt-cache policy nodejs
nodejs:
  Installed: 8.12.0-1nodesource1
  Candidate: 8.15.1-1nodesource1
  Version table:
     8.15.1-1nodesource1 0
        500 https://deb.nodesource.com/node_8.x/ jessie/main armhf Packages
 *** 8.12.0-1nodesource1 0
        100 /var/lib/dpkg/status
     0.10.29~dfsg-2 0
        500 http://mirrordirector.raspbian.org/raspbian/ jessie/main armhf Packages

```

That one is still on Jessie, but I don't think that has changed.  
At which point I notice that this pi is out of date.

---

<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:** [10 March 2019 16:33 UTC](https://discourse.nodered.org/t/pi-install-nodejs-question/8800/7 "2019-03-10T16:33:38Z")

</div>

Sorry, corrected above.
