30

I was lucky enough to get a Raspberry Pi under the tree this year and I've had a bit of fun playing with Node.js on the device. However, Node.js is much more interesting when you can pull down packages and plug them into your applications - and this is where I am having some trouble.

If I attempt to install NPM along with Node.js with the following command:

sudo apt-get install nodejs npm

I get the following error:

pi@raspberrypi ~ $ sudo apt-get install nodejs npm
Reading        package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 nodejs : Breaks: npm (< 1.1.4~dfsg-2~) but 1.1.4~dfsg-1 is to be installed
 npm : Depends: node-semver but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

I'm pretty new to how package management works with Debian-based Linux operating systems and don't know much at all about how the node.js community has structured their specific packages. It is worth noting that installing node.js by itself works just fine, and if I try to install NPM just by itself this is what I get.

pi@raspberrypi ~ $ sudo apt-get install npm
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 npm : Depends: nodejs but it is not going to be installed
       Depends: nodejs-dev but it is not going to be installed
       Depends: node-request but it is not going to be installed
       Depends: node-mkdirp but it is not going to be installed
       Depends: node-minimatch but it is not going to be installed
       Depends: node-semver but it is not going to be installed
       Depends: node-ini but it is not going to be installed
       Depends: node-graceful-fs but it is not going to be installed
       Depends: node-abbrev but it is not going to be installed
       Depends: node-nopt but it is not going to be installed
       Depends: node-fstream but it is not going to be installed
       Depends: node-rimraf but it is not going to be installed
       Depends: node-tar but it is not going to be installed
       Depends: node-which but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

I'm not sure, but my gut is telling me that it is something to do with the node-semver package. If I install the nodejs package by itself and then attempt to install node-semver this is the output that I get.

pi@raspberrypi ~ $ sudo apt-get install node-semver
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 node-semver : Depends: nodejs but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Any pointers?

0

9 Answers 9

25

Try installing them all together:

sudo apt-get install nodejs npm node-semver
35

This is the best way to install NodeJs on raspberry pi, i love that way, and i think it's easy to to do, and later for update just replace the '/opt/nodejs' folder with the new release:

wget https://nodejs.org/dist/v4.2.4/node-v4.2.4-linux-armv6l.tar.gz

sudo mv node-v4.2.4-linux-armv6l.tar.gz /opt

cd /opt

sudo tar -xzf node-v4.2.4-linux-armv6l.tar.gz

sudo mv node-v4.2.4-linux-armv6l nodejs

sudo rm node-v4.2.4-linux-armv6l.tar.gz

sudo ln -s /opt/nodejs/bin/node /usr/bin/node

sudo ln -s /opt/nodejs/bin/npm /usr/bin/npm

Note that there is also an arm71 version for the last Raspberry versions.

4
  • 2
    This answer is the up-to-date one.
    – Uriel
    Commented Dec 31, 2015 at 13:53
  • 1
    This was the best solution so far but I just found another, using nvm (Node Version Manager) which also allows you to easily update node but also use different versions at the same time. They share the symlink steps to allow node access for all users. A short tutorial here losant.com/blog/how-to-install-nodejs-on-raspberry-pi with a solution to avoid the symlink issues: stackoverflow.com/a/29903645/3480671
    – bosch
    Commented Sep 25, 2016 at 13:29
  • NB: /usr/local/bin would be slightly more appropriate for local-admin-managed symbolic links to a local-admin-managed filedump in /opt Commented Jun 16, 2018 at 12:53
  • it worked for me, the actual issue I was having is that NPM didn't come with node, but NPM didn't exist as a standalone, this got NPM installed, but now Node doesn't work
    – J-Cake
    Commented Feb 26, 2019 at 6:31
4

Adafruit provides a (relatively) current node and npm. After not finding a compile helpful this worked for me with a number of packages (express, body-parser, pg)

3

I find the easiest way to get NPM (and the latest version of Node.js) on any Raspberry PI (Zero to 3) is to use "NVM" (Node Version Manager).

To install NVM:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.6/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

Once installed, you can download the latest version of Node.js at any time like so:

nvm install node

Done!

Verify NPM is installed:

npm --version
1
  • This worked well for me on my pi 3b+ the first solution installed npm 1.6 and kept running into errors when installing packages. NVM got things up and running properly.
    – sirclesam
    Commented Jun 10, 2019 at 23:40
2

I run raspbian jessie on pi 3. Node comes pre-installed in the image but npm does not. Had challenges in installing npm and this thread helped me get clues.

The error I received was

pi@raspberrypi:~ $ **sudo apt-get install nodejs npm node-semver**
Reading package lists... Done
Building dependency tree       
Reading state information... Done
nodejs is already the newest version.
nodejs set to manually installed.
The following extra packages will be installed:
  gyp libc-ares-dev libjs-node-uuid libjs-underscore libssl-dev 
  libssl-doc libv8-3.14-dev node-abbrev node-ansi node-ansi-color-table 
  node-archy node-async node-block-stream node-combined-stream 
  node-cookie-jar node-delayed-stream node-forever-agent node-form-data 
  node-fstream node-fstream-ignore node-github-url-from-git node-glob 
  node-graceful-fs node-gyp node-inherits node-ini node-json-stringify-safe
  node-lockfile node-lru-cache node-mime node-minimatch
  node-mkdirp node-mute-stream node-node-uuid node-nopt node-normalize-package-data
  node-npmlog node-once node-osenv node-qs node-read node-read-package-json
  node-request node-retry node-rimraf node-sha node-sigmund node-slide 
  node-tar node-tunnel-agent node-underscore node-which nodejs-dev
Suggested packages:
  node-hawk node-aws-sign node-oauth-sign node-http-signature
The following NEW packages will be installed:
  gyp libc-ares-dev libjs-node-uuid libjs-underscore libssl-dev 
  libssl-doc libv8-3.14-dev node-abbrev node-ansi node-ansi-color-table 
  node-archy node-async node-block-stream node-combined-stream 
  node-cookie-jar node-delayed-stream node-forever-agent node-form-data   
  node-fstream node-fstream-ignore node-github-url-from-git node-glob 
  node-graceful-fs node-gyp node-inherits node-ini node-json-stringify-safe
  node-lockfile node-lru-cache node-mime node-minimatch
  node-mkdirp node-mute-stream node-node-uuid node-nopt node-normalize-package-data
  node-npmlog node-once node-osenv node-qs node-read node-read-package-json
  node-request node-retry node-rimraf node-semver node-sha node-sigmund 
  node-slide node-tar node-tunnel-agent node-underscore node-which  
  nodejs-dev npm
0 upgraded, 55 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,222 kB/3,708 kB of archives.
After this operation, 13.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
**Err http://mirrordirector.raspbian.org/raspbian/ jessie/main libssl-dev armhf 1.0.1k-3+deb8u2
  404  Not Found [IP: 5.153.225.207 80]
Err http://mirrordirector.raspbian.org/raspbian/ jessie/main libssl-doc all 1.0.1k-3+deb8u2
  404  Not Found [IP: 5.153.225.207 80]
E: Failed to fetch 
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?**
pi@raspberrypi:~ $ 

The below 2 commands in sequence helped me

sudo apt-get update
sudo apt-get install npm
1
  • 3
    Could you please edit your post to make it more readable. Is the wall of text really necessary?
    – Ghanima
    Commented Apr 24, 2016 at 15:01
1

If you are running into problems with the binary packages I'd recommend you compile it yourself, this way you get a better idea of while something is failing/the binary packages may be for a different type of processor (not ARM).

I suggest checking out https://gist.github.com/3301813 for Raspberry Pi NodeJS Compiling instructions.

2
  • Thanks Ben. I had come across that article before. I assumed that NPM might be separate to the Node.js source tree?
    – Mitch Denny
    Commented Dec 27, 2012 at 2:39
  • NPM is separate at source github.com/isaacs/npm however the recent versions for nodejs generally come with npm bundled.
    – Ben Evans
    Commented Dec 27, 2012 at 21:13
1

As Ben pointed out I'd suggest to compile Node.js on your own on the Raspberry Pi. Since 0.8.10 (or so) this is possible without further ado. Simply

$ ./configure
$ make
$ sudo make install

and that's it. Then Node.js will be installed including npm.

Works like a charme :-)!

3
  • Thanks Golo. Minitech provided an answer which worked better for me. The Raspberry Pi is quite slow so I would think that building, then installing would be a bit more painful.
    – Mitch Denny
    Commented Dec 27, 2012 at 23:05
  • 1
    Please have a look at the version of Node.js being installed using apt-get, and then compare this version to the current version of Node.js, and you'll know why I did not suggest to use apt-get ... ;-)
    – Golo Roden
    Commented Jan 3, 2013 at 12:38
  • I've made some pre-compiled tarballs that can be used on a Raspberry Pi if you don't really want to wait for the source to compile. gist.github.com/3245130
    – Adam M-W
    Commented Jun 18, 2013 at 4:37
1

All you do is type in

pi@raspberrypi ~ $ sudo apt-get install nodejs npm node-semver 

It worked for me and I was able to install it with no errors and it should work with a program!

1
  • 1
    Please be more precise: what version of node did you install this way, what was the package source (did you add a new one?), what OS did you install onto, what rPi version do you have, what node arch is it (armv6, v7). You answer might solve something but we don't know what so noone will use it.
    – bosch
    Commented Sep 25, 2016 at 12:36
0

Try to follow this post. I manage to run npm on /opt/node/npm, but when I copy it to /usr/bin/ it misses 'npmlog'.

1
  • IT is preferred that you copy the steps into the answer while attributing your source for additional information, in case the source site goes down, page is deleted or moved, etc. At least a summary of the broad strokes of the process.
    – Tevo D
    Commented Aug 23, 2013 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.