# Installing nodejs on a Raspberry Pi Zero

> By Simon W. Jackson.
>
> Web version: https://simonwjackson.io/posts/install-node-js-on-raspberry-pi-zero/
> Published: 2019-09-13

I recently switched one of my projects from a Raspberry Pi 3 over to a Raspberry Pi Zero. Since they both run _very_ similar hardware, I was able to just pop out the sdcard from the Rpi 3 and just insert it into the zero and voilà everything just worked.. or so I thought.


I recently switched one of my projects from a [Raspberry Pi 3](https://www.amazon.com/Raspberry-Pi-RASP-PI-3-Model-Motherboard/dp/B01CD5VC92?tag=miniarray-20) over to a [Raspberry Pi Zero](https://www.amazon.com/Raspberry-Pi-RASP-PI-3-Model-Motherboard/dp/B01CD5VC92?tag=miniarray-20). Since they both run _very_ similar hardware, I was able to just pop out the sdcard from the Rpi 3 and just insert it into the zero and _Voilà_ everything just worked.. or so I thought.

The main app(s) I was using to serve up a couple of pages was no longer working. `npm` and `nodejs`. But, after doing a bit o' research, I found that `node` requires special compilation instructions for the different ARM chips:

> "Unfortunately this is because RaspPi is ARMv6 while the 'armhf' Debian distro is for ARMv7 and above. We need to have an arch check in the setup script to make sure this is stated at install time." - [rvagg, Dec 6, 2014](https://github.com/nodesource/distributions/issues/44#issuecomment-65916201)

Luckily, there is a solution:

First, we will need to download an earlier version of node (v4.2.4) built specifically for armv6l

```bash
$ cd ~
$ wget http://nodejs.org/dist/v4.2.4/node-v4.2.4-linux-armv6l.tar.gz
```

Now, extract it to the `/usr/local` directory

```bash
$ cd /usr/local
$ sudo tar xzvf ~/node-v4.2.4-linux-armv6l.tar.gz --strip=1
```

Finally, (if you haven't already) remove the nodejs debian package

```bash
$ sudo apt-get remove --purge npm node nodejs
```

Now we can verify that everything is good to go:

```bash
$ node -v
v4.2.4
```

## Optional (but highly recommended)

This install method comes with npm version 2.x which is known for slow installs due to the method in which it handles dependencies. We can upgrade it easily with the following command:

```bash
$ sudo npm install -g npm
```

So meta.

## Refrences

*   [Segfaults on Raspberry Pi with Raspbian Wheezy](https://github.com/nodesource/distributions/issues/44#issuecomment-172850379)
*   [How can I update Node.js and NPM to the next versions?](http://stackoverflow.com/questions/6237295/how-can-i-update-node-js-and-npm-to-the-next-versions)
