Install Node.js and Npm on Raspberry Pi

268,882

31

26

Introduction: Install Node.js and Npm on Raspberry Pi

About: Raspberry Pi fan.

You can build many apps using node.js and npm on your raspberry pi and it's very easy to interact with GPIO or other components connected to your raspberry pi. So if you are like me and like to do it on node.js here a few simple steps to install node and npm.

Step 1: Detect What Version of Node.js You Need

The processor on Raspberry Pi is ARM, but depends on the model there can be ARMv6, ARMv7 or ARMv8. This 3 versions of ARM is supported by Node.js.

So first of all type this in your terminal on raspberry pi to detect the version that you need:

uname -m

If the response starts with armv6 than that's the version that you will need. For example for raspberry pi zero W you will need ARMv6

Step 2: Download Node.JS Linux Binaries for ARM

Go to node.js download page and check right click on the version of ARM that you need and choose Copy Link address.

After that in the terminal using wget download the tar.gz file for that version. Just type wget, paste the link copied before and make sure the extension is .tar.gz. If it's something else change it to this and it should be ok. For example I will need ARMv6 and I will type this in my terminal:

wget https://nodejs.org/dist/v8.9.0/node-v8.9.0-linux-armv6l.tar.gz

Step 3: Extract the Archive

Using tar that is already installed with the system on your raspberry pi just type this (make sure you change the filename with the file that you have)

tar -xzf node-v8.9.0-linux-armv6l.tar.gz

Step 4: Copy Node to /usr/local

cd node-v6.11.1-linux-armv6l/

sudo cp -R * /usr/local/

Step 5: Check If Everything Is Installed Ok

Check if node and npm are installed correctly. This lines should print the version of node and npm installed.

node -v

npm -v

Now you have node.js installed on your Raspberry Pi and working so you can build something using node

Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017

8 People Made This Project!

Recommendations

  • Fix It Speed Challenge

    Fix It Speed Challenge
  • Anything Goes Contest 2021

    Anything Goes Contest 2021
  • New Year, New Skill Student Design Challenge

    New Year, New Skill Student Design Challenge

26 Comments

0
AndrewA224
AndrewA224

7 months ago

Thanks! This post is very usefull for me! I`m making a small local server with NodeJS.

0
stingray124
stingray124

Question 10 months ago on Step 3

HELP !!! I have been trying to install magic mirror on a pi model 3b +.
and i get error about hardware ARMv6 is not compatable!!!
Is that true ? or can I get past that some how ?

0
biskis
biskis

Answer 10 months ago

pi 3b + is ARM v7. You need to install form ARM 7

0
RoyH68
RoyH68

11 months ago on Step 3

STEP 3 : I had to use tar -xvf instead of xzf because the file isnt in zip format

0
hlesta
hlesta

1 year ago

Thanks so much, it was helpful.

0
bb_matt
bb_matt

1 year ago

Or you can just run:
sudo apt-get install nodejs -y

0
andytilia
andytilia

1 year ago

or type tar -xzf <TAB> to autocomplete the awkward file name.

0
satscape
satscape

Tip 2 years ago on Step 5

It's also in the raspbian repo.
sudo apt install nodejs npm -y
It may put it in /usr/bin/ and not /usr/sbin
So if it says it can't find it, type: /usr/bin/node -v

0
MohitP13
MohitP13

Question 2 years ago

after follow all this step , at last when i run node -v to check , it's working or not .
it show me
-bash: /usr/local/bin/node: No such file or directory
plz solve help

Capture.PNG
0
scout208
scout208

2 years ago

If you just use `tar xf <name of the archive>` it will work with any format (xz or gz).

0
storkweb.test
storkweb.test

Tip 2 years ago on Step 3

If the archive file is in .tar.xz format (i.e. arm v7) then the command to unzip it is :
tar -xJf <name of the archive.tar.xz>

0
ShashiK3
ShashiK3

2 years ago

Worked on first try. Thanks. ( Although I had to first copy from the Node.js site to my local workstation, and then scp to my Rpi )

0
bestcs2017
bestcs2017

Question 2 years ago on Step 1

i m using raspbian pi3 b+ model nd processor is ARMv8.M doing a project of Magic Mirror.M facing a problem when installing npm. Error is shown that npm is not supported node js version.it suggested me to install node js version 4,6,7,8,9 where in my system node js 10.15.2 has already been installed.Could u plz suggest me the command line code for installation of nodejs version 8 with arm8 processor

0
SergioL34
SergioL34

2 years ago

Thanks,
It worked at the first try.

0
JihyeongL
JihyeongL

Question 3 years ago on Step 5

I've followed this except version of node since the latest version of it is 8.11.3 and my architecture is ARMv7. After copying things to /usr/loacl, I checked node -v. It worked. But when I typed npm -v, the output was bash: /usr/bin/npm: there's no such file or directory. What should I do to fix this? Please help.

0
JihyeongL
JihyeongL

Answer 3 years ago

solved. npm was in /usr/local/bin so I made link to /usr/bin.

0
Martinkirkby
Martinkirkby

Reply 2 years ago

Hello
how did you make a link?
i have the same prob

0
JihyeongL
JihyeongL

Reply 2 years ago

Just do ln -s (original file) (target file). It will make a symbolic link of a file. If you are trying to make a link to a root-permission-required directory, you should do it as a root. Change your user account by su (target account) or just su for root. Or you can do with sudo if possible.

0
Nickdebesten
Nickdebesten

Question 2 years ago on Step 5

It does not worm for me node and npm :-(