如何在 Raspberry Pi 上安装最新版本的 node.js?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42741243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you install newest version of node.js on Raspberry Pi?
提问by rynop
I want to install the latest stable version of Node.js on Raspberry Pi 3. How do I do it in such a way that a) I'm always able to update to latest LTS version b) Can easily switch between versions
我想在 Raspberry Pi 3 上安装 Node.js 的最新稳定版本。我如何做到 a) 我总是能够更新到最新的 LTS 版本 b) 可以轻松地在版本之间切换
回答by rynop
The Node version managerworks great, even for ARM based processors (like Raspberry Pi).
该节点版本管理的伟大工程,即使是基于ARM处理器(如树莓派)。
You need to remove the existing version of node installed on Raspbian however (if you are using this distro):
但是,您需要删除安装在 Raspbian 上的现有节点版本(如果您使用的是此发行版):
Remove old:
删除旧的:
sudo -i
apt-get remove nodered -y
apt-get remove nodejs nodejs-legacy -y
exit
Install n (it will also install latest stable Node.js):
安装 n(它还将安装最新的稳定 Node.js):
curl -L https://git.io/n-install | bash
curl -L https://git.io/n-install | bash
Verify:
核实:
pi@raspberrypi:~ $ node --version
nv7.6.0
pi@raspberrypi:~ $ npm --version
4.1.2
回答by Sawtaytoes
If you've installed nvm, you can use nvm install latestor nvm install stable.
如果您已安装 nvm,则可以使用nvm install latest或nvm install stable。
That's the best way to keep it up-to-date. You could write a bash script to handle keeping your Node.js version in sync with the latest using nvm.
这是保持最新状态的最佳方式。您可以编写一个 bash 脚本来使用 nvm 处理使您的 Node.js 版本与最新版本保持同步。

