Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com Dec 28 '12 at 0:08

This question came from our site for professional and enthusiast programmers.

up vote 5 down vote accepted

Try installing them all together:

sudo apt-get install nodejs npm node-semver
share|improve this answer

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.

share|improve this answer
    
This answer is the up-to-date one. – Uriel Dec 31 '15 at 13:53

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)

share|improve this answer

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.

share|improve this answer
    
Thanks Ben. I had come across that article before. I assumed that NPM might be separate to the Node.js source tree? – Mitch Denny Dec 27 '12 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 Dec 27 '12 at 21:13
    
Thanks for the info Ben. Appreciate it. – Mitch Denny Dec 27 '12 at 23:31

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 :-)!

share|improve this answer
    
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 Dec 27 '12 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 Jan 3 '13 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 Jun 18 '13 at 4:37

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

share|improve this answer
    
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 Aug 23 '13 at 13:07

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!

share|improve this answer

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
share|improve this answer
1  
Could you please edit your post to make it more readable. Is the wall of text really necessary? – Ghanima Apr 24 at 15:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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