我正在尝试在我的Raspberry Pi(Raspbian)上安装node-hid。 但是node-hid需要高版本的Nodej才能工作(> = 0.8),而我的版本只有0.6.19。
所以,我尝试用nvm安装Nodejs v0.10.26 ... Nvm成功安装了nodejs v0.10.26,但是npm仍然使用旧版本的Nodejs。如何在整个系统中使用v0.10.26版本的Nodej?我该如何安装node-hid?
感谢您的帮助
以下是我在尝试安装node-hid时获得的代码:
pi@raspberrypi ~ $ sudo npm install -g node-hid
npm http GET https://registry.npmjs.org/node-hid
npm ERR! Error: failed to fetch from registry: node-hid
npm ERR! at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR! at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
npm ERR! at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
npm ERR! at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
npm ERR! at Request.<anonymous> (/usr/lib/nodejs/request/main.js:212:58)
npm ERR! at Request.emit (events.js:88:20)
npm ERR! at ClientRequest.<anonymous> (/usr/lib/nodejs/request/main.js:209:10)
npm ERR! at ClientRequest.emit (events.js:67:17)
npm ERR! at ClientRequest.onError (/usr/lib/nodejs/request/tunnel.js:164:21)
npm ERR! at ClientRequest.g (events.js:156:14)
npm ERR! You may report this log at:
npm ERR! <http://bugs.debian.org/npm>
npm ERR! or use
npm ERR! reportbug --attach /home/pi/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.6.11+
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "node-hid"
npm ERR! cwd /home/pi
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.4
npm ERR! message failed to fetch from registry: node-hid
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/pi/npm-debug.log
npm not ok
在npm-debug.log中:
info it worked if it ends with ok
verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'install', 'node-hid', '-g' ]
info using npm@1.1.4
info using node@v0.6.19
verbose config file /root/.npmrc
verbose config file /usr/etc/npmrc
verbose config file /usr/share/npm/npmrc
silly exec /usr/bin/nodejs "/usr/share/npm/bin/npm-get-uid-gid.js" "nobody" 1000
silly spawning [ '/usr/bin/nodejs',
silly spawning [ '/usr/share/npm/bin/npm-get-uid-gid.js', 'nobody', 1000 ],
silly spawning null ]
silly output from getuid/gid {"uid":65534,"gid":1000}
silly output from getuid/gid
verbose cache add [ 'node-hid', null ]
silly cache add: name, spec, args [ undefined, 'node-hid', [ 'node-hid', null ] ]
verbose parsed url { pathname: 'node-hid', path: 'node-hid', href: 'node-hid' }
verbose addNamed [ 'node-hid', '' ]
verbose addNamed [ null, '' ]
silly name, range, hasData [ 'node-hid', '', false ]
verbose raw, before any munging node-hid
verbose url resolving [ 'https://registry.npmjs.org/', './node-hid' ]
verbose url resolved https://registry.npmjs.org/node-hid
http GET https://registry.npmjs.org/node-hid
ERR! Error: failed to fetch from registry: node-hid
ERR! at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
ERR! at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
ERR! at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
ERR! at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
ERR! at Request.<anonymous> (/usr/lib/nodejs/request/main.js:212:58)
ERR! at Request.emit (events.js:88:20)
ERR! at ClientRequest.<anonymous> (/usr/lib/nodejs/request/main.js:209:10)
ERR! at ClientRequest.emit (events.js:67:17)
ERR! at ClientRequest.onError (/usr/lib/nodejs/request/tunnel.js:164:21)
ERR! at ClientRequest.g (events.js:156:14)
ERR! You may report this log at:
ERR! <http://bugs.debian.org/npm>
ERR! or use
ERR! reportbug --attach /home/pi/npm-debug.log npm
ERR!
ERR! System Linux 3.10.25+
ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "node-hid" "-g"
ERR! cwd /home/pi
ERR! node -v v0.6.19
ERR! npm -v 1.1.4
ERR! message failed to fetch from registry: node-hid
verbose exit [ 1, true ]
答案 0 :(得分:5)
sudo apt-get update
sudo apt-get upgrade
sudo wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
node -v
不完全确定是否全部需要(有些可能已安装),但这是唯一对我有用的东西..
sudo apt-get install g++ curl
sudo apt-get install libssl-dev apache2-utils
sudo apt-get install build-essential
sudo apt-get install pkg-config
sudo npm install node-gyp -g
sudo apt-get install git-core
sudo apt-get install libudev-dev
sudo apt-get install libusb-1.0-0-dev
npm install node-hid
注意:上面的节点安装仅适用于Raspbian,如果您想在Ubuntu中进行实验,请使用以下代码来安装节点,其他一切保持不变:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs