node.js 和 node 有什么区别? [英] What are the differences between node.js and node?
问题描述
我已经在我的机器上安装了 node.js (linux mint 15),当我运行 node example.js
时,它说:
I've installed node.js in my machine (linux mint 15), when I run node example.js
, it says:
The program 'node' can be found in the following packages:
* node
* nodejs-legacy
Try: sudo apt-get install <selected package>
那么node和nodejs有什么区别呢?我之前安装了 node.js 和 node,但是当我运行 node example.js
时,Web 服务器根本没有启动.所以我删除了节点并保留了 node.js.
So what are the differences between node and nodejs? I had both node.js and node installed previously, but when I run node example.js
, the web server doesn't start at all. So I deleted node and kept node.js.
推荐答案
包节点与node.js无关.
The package node is not related to node.js.
nodejs
是您想要的,但是为了与使用 #!/usr/bin/env node
的脚本兼容,将命令称为 node 可以说更好.
nodejs
is what you want, however it is arguably better to have the command be called node for compatibility with scripts that use #!/usr/bin/env node
.
您可以只在路径中创建一个符号链接:
You can either just create a symlink in your path:
sudo ln -s `which nodejs` /usr/local/bin/node
或者你可以安装 nvm 然后用它来安装最新版本的node.js:
Or you could install nvm and then use it to install the latest version of node.js:
nvm install stable
我更喜欢 nvm 方法,因为它允许您sudo apt-get remove nodejs
,然后管理您自己使用的节点版本.您还可以安装多个版本的 node.js,并使用 nvm use
在它们之间轻松切换.
I prefer the nvm method, as it allows you to sudo apt-get remove nodejs
, and then manage which version of node you're using yourself. You can also have multiple versions of node.js installed and use nvm use <version>
to easily switch between them.
我还喜欢在 .bashrc
的底部添加一行,例如:nvm use stable >/dev/null
.这将自动使用您安装的最新版本.
I also like to add a line to the bottom my .bashrc
like: nvm use stable > /dev/null
. That will automatically use the latest version you have installed.
要将您的节点版本更新到最新的稳定版:nvm install stable
.每次执行此操作时,如果您想继续使用它们,您都需要安装已全局安装的任何 npm 包.
To update your node version to the latest stable: nvm install stable
. Every time you do this you will need to install any npm packages that you had installed globally if you want to continue using them.
要切换到旧版本,只需运行 nvm use
,或者,如果您尚未安装旧版本:nvm install
代码>.
To switch to an old version just run nvm use <version>
, or, if you don't have the old version installed already: nvm install <version>
.
这篇关于node.js 和 node 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!