在Raspberry Pi上安装NPM(Wheezy映像)


28

今年我很幸运能在树下得到一台Raspberry Pi,在设备上玩Node.js时我感到很开心。但是,当您可以拉出软件包并将其插入应用程序时,Node.js会更有趣-这就是我遇到麻烦的地方。

如果我尝试使用以下命令将NPM与Node.js一起安装:

sudo apt-get install nodejs npm

我收到以下错误:

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.

我对软件包管理如何与基于Debian的Linux操作系统一起使用还很陌生,并且对node.js社区如何构建其特定软件包一无所知。值得注意的是,单独安装node.js可以正常工作,如果我尝试单独安装NPM,这就是我得到的。

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.

我不确定,但是我的直觉告诉我这与node-semver包装有关。如果我自己安装nodejs软件包,然后尝试安装,则node-semver这是我得到的输出。

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.

有指针吗?

Answers:


22

尝试将它们全部安装在一起:

sudo apt-get install nodejs npm node-semver

32

这是在树莓派上安装NodeJ的最佳方法,我喜欢这种方式,而且我认为这很容易做到,以后进行更新时,只需用新版本替换'/ opt / nodejs'文件夹即可:

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

请注意,最后的Raspberry版本也有arm71版本。


2
这个答案是最新的。
Uriel 2015年

1
这是迄今为止最好的解决方案,但我刚刚找到了另一个使用nvm(节点版本管理器)的解决方案,它还可以使您轻松更新节点,但同时也可以使用不同的版本。它们共享符号链接步骤,以允许所有用户访问节点。这里有一个简短的教程losant.com/blog/how-to-install-nodejs-on-raspberry-pi,其中提供了一种避免符号链接问题的解决方案:stackoverflow.com/a/29903645/3480671
bosch

注意:/usr/local/bin对于本地管理员管理的指向本地管理员管理的文件转储的符号链接,稍微合适一些/opt
JamesTheAwesomeDude

它对我有用,我真正遇到的问题是NPM并未随Node一起提供,但NPM并没有独立存在,因此安装了NPM,但现在Node不起作用
Jacob Schneider

4

Adafruit提供(相对)当前节点和npm。在没有找到有用的编译器之后,这对我使用了许多软件包(express,body-parser,pg)起作用


2

我在pi 3上运行raspbian jessie。该节点已预安装在映像中,但npm并未安装。在安装npm时遇到了挑战,该线程帮助我获得了线索。

我收到的错误是

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:~ $ 

以下2条命令依次对我有帮助

sudo apt-get update
sudo apt-get install npm

3
您能否编辑您的帖子以使其更具可读性。文字墙真的必要吗?
加纳马马

2

我发现在任何Raspberry PI(零至3)上获取NPM(以及最新版本的Node.js)的最简单方法是使用“ NVM”(节点版本管理器)。

要安装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

安装后,您可以随时下载最新版本的Node.js,如下所示:

nvm install node

做完了!

确认已安装NPM:

npm --version

这对我的pi 3b +来说效果很好,第一个解决方案安装了npm 1.6,并且在安装软件包时一直出错。NVM使一切正常运行。
sirclesam

1

如果您遇到二进制程序包的问题,​​我建议您自己编译它,这样可以更好地了解出现故障的情况/二进制程序包可能用于其他类型的处理器(非ARM)。

我建议查看https://gist.github.com/3301813以获取Raspberry Pi NodeJS编译说明。


谢谢本。我以前看过那篇文章。我以为NPM可能与Node.js源代码树分开?

NPM在源代码github.com/isaacs/npm处是单独的,但是nodejs的最新版本通常捆绑了npm。

1

正如Ben指出的那样,我建议您在Raspberry Pi上自行编译Node.js。从0.8.10(或大约)开始,这是没有可能的事。只是

$ ./configure
$ make
$ sudo make install

就是这样。然后将安装Node.js,其中包括npm

像一个咒语:-)!


感谢Golo。Minitech提供了一个对我来说更好的答案。Raspberry Pi相当慢,所以我认为构建然后安装会比较痛苦。

1
请查看使用安装的Node.js版本apt-get,然后将其与当前版本的Node.js进行比较,您会知道为什么我不建议使用apt-get... ;-)
Golo Roden

我已经制作了一些预编译的tarball,可以在Raspberry Pi上使用,如果您真的不想等待源代码编译的话。gist.github.com/3245130
亚当MW

1

您要做的就是输入

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

它为我工作,并且我能够没有错误地安装它,并且它应该与程序一起工作!


1
请更精确:您以这种方式安装了哪个版本的节点,软件包的来源是什么(是否添加了新的软件包?),安装了什么操作系统,安装了哪个rPi版本,它是什么节点架构( armv6,v7)。您的回答可能会解决一些问题,但我们不知道该怎么做,因此没人会使用它。
博世

0

尝试关注此帖子。我设法在/ opt / node / npm上运行npm,但是当我将其复制到/ usr / bin /时,它会丢失'npmlog'。


IT部门最好将步骤复制到答案中,同时在源中分配其他信息,以防源站点出现故障,页面被删除或移动等情况。至少是该过程的概括。
Tevo D
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.