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?

Marius Butuc
  • 925
  • 3
  • 11
  • 20
Mitch Denny
  • 401
  • 1
  • 4
  • 5

9 Answers9

36

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.

Uriel
  • 103
  • 2
25

Try installing them all together:

sudo apt-get install nodejs npm node-semver
Ry-
  • 369
  • 3
  • 9
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)

real_paul
  • 123
  • 5
user542319
  • 163
  • 4
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
Wireblue
  • 131
  • 3
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
Bex
  • 2,929
  • 3
  • 26
  • 34
Krishnan V
  • 21
  • 1
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.

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

Golo Roden
  • 323
  • 1
  • 3
  • 9
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!

Greenonline
  • 2,969
  • 5
  • 27
  • 38
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'.