ubuntu 12.04 上的 nodejs 与 node

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18130164/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:15:11  来源:igfitidea点击:

nodejs vs node on ubuntu 12.04

javascriptnode.jsubuntuserverside-javascript

提问by Jatin

I installed nodejs on ubuntu from instructions given here

我根据此处给出的说明在 ubuntu 上安装了 nodejs

When I write node --versionin the terminal I see this :
-bash: /usr/sbin/node: No such file or directory

当我node --version在终端写我看到这个:
-bash: /usr/sbin/node: No such file or directory

I can see node in the /usr/sbin/directory, though.

不过,我可以在/usr/sbin/目录中看到节点。

Writing npm --versionshows 1.3.5
Writing nodejs --versionshows v0.10.15

写作npm --version节目1.3.5
写作nodejs --version节目v0.10.15

Also, I can see node in the /usr/bin/directory.

另外,我可以在/usr/bin/目录中看到节点。

So, how do I get nodeworking?

那么,我如何开始node工作?

Also, If I use zshinstead of bash, then nodecommand works.

另外,如果我使用zsh而不是 bash,则node命令有效。

回答by randunel

You need to manually create a symlink /usr/bin/node. Shortcut for bash compatible shells:

您需要手动创建一个符号链接/usr/bin/node。bash 兼容 shell 的快捷方式:

sudo ln -s `which nodejs` /usr/bin/node

Or if you use non-standard shells, just hardcode the path you find with which nodejs:

或者,如果您使用非标准外壳,只需硬编码您找到的路径which nodejs

sudo ln -s /usr/bin/nodejs /usr/bin/node

Later edit

稍后编辑

I found this explanation in the link you posted

我在你发布的链接中找到了这个解释

There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed from node to nodejs. You'll need to symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.

与节点包(Amateur Packet Radio Node Program)存在命名冲突,nodejs二进制已经从node重命名为nodejs。您需要将 /usr/bin/node 符号链接到 /usr/bin/nodejs 或者您可以卸载 Amateur Packet Radio Node Program 以避免这种冲突。

Later later edit

稍后编辑

It's been a while since I answered this. Although the solution I posted up here worked for me several times, users have reported a few more solutions within the comments:

我已经有一段时间没有回答这个问题了。尽管我在这里发布的解决方案对我有用过几次,但用户在评论中报告了更多解决方案:

From @user229115

来自@user229115

sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

From AskUbuntu (user leftium)

来自 AskUbuntu(用户 leftium)

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs

回答by user229115

I think this is it:

我觉得这就是:

sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

Using Debian alternatives.

使用 Debian 替代品。

回答by Tino

Apparently the solution differs between Ubuntu versions. Following worked for me on Ubuntu 13.10:

显然,Ubuntu 版本之间的解决方案有所不同。以下在 Ubuntu 13.10 上对我有用:

sudo apt-get install nodejs-legacy

HTH

HTH

Edit: Rule of thumb:

编辑:经验法则:

If you have installed nodejsbut are missing the /usr/bin/nodebinary, then also install nodejs-legacy.This just creates the missing softlink.

如果您已安装nodejs但缺少/usr/bin/node二进制文件,则还要安装nodejs-legacy. 这只会创建丢失的软链接。

According to my tests, Ubuntu 17.10 and above already have the compatibility-softlink /usr/bin/nodein place after nodejsis installed, so nodejs-legacyis missing from these releases as it is no more needed.

根据我的测试,Ubuntu 17.10 及更高版本/usr/bin/nodenodejs安装后已经具有兼容性软链接,因此nodejs-legacy这些版本中缺少它,因为不再需要它。

回答by Dmytro Medvid

I have the same issue in Ubuntu 14.04.

我在 Ubuntu 14.04 中遇到了同样的问题。

I have installed "nodejs" and it's working, but only if I'm use command "nodejs". If I try to use "node" nothing happens.

我已经安装了“nodejs”并且它正在工作,但前提是我使用命令“nodejs”。如果我尝试使用“节点”,则什么也不会发生。

I'm fixed this problem in next way:

我用下一种方式解决了这个问题:

  1. Install nodejs-legacy

    sudo apt-get install nodejs-legacy
  1. 安装 nodejs-legacy

    sudo apt-get install nodejs-legacy

After that, when I type "node" in command line I'm get an error message "/usr/sbin/node: No such file or directory"

之后,当我在命令行中键入“node”时,我收到一条错误消息“/usr/sbin/node: No such file or directory”

  1. Second, what I did, it's a symbolic link on "nodejs":

    sudo ln -s /usr/bin/nodejs /usr/sbin/node
  1. 其次,我所做的是“nodejs”上的符号链接:

    sudo ln -s /usr/bin/nodejs /usr/sbin/node

回答by CHsurfer

This happened to me as well.

这也发生在我身上。

node -v => 0.10.2
nodejs -v => 5.5.0

The issue was that I had installed node from source some time ago. Running

问题是我前段时间从源代码安装了节点。跑步

which node

always pointed to this local installation. Also,

总是指向这个本地安装。还,

echo NODE_PATH

pointed to the local installation.

指向本地安装。

deleting the directory with the source install didn't help. It just broke the node command. In the end, unsetting the NODE_PATH environmental variable and purging then reinstalling nodejs did the trick.

删除带有源安装的目录没有帮助。它只是破坏了节点命令。最后,取消设置 NODE_PATH 环境变量并清除然后重新安装 nodejs 就成功了。

unset NODE_PATH
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs

After this,

在这之后,

node -v => 5.5.0

and npm install started to work for packages depending on Node => 5.0.

并且 npm install 开始为依赖于 Node => 5.0 的包工作。

回答by Rotareti

Node Version Manager (nvm)

节点版本管理器 (nvm)

If you like to install multiple nodejs versions and easily switch between them, I would suggest using Node Version Manger. It also solves the naming problem (nodevs nodejs)

如果您喜欢安装多个 nodejs 版本并在它们之间轻松切换,我建议您使用Node Version Manger。它还解决了命名问题(nodevs nodejs

It's quite simple:

这很简单:

Install a nodejs version:

安装 nodejs 版本:

$ nvm install 4.4

Now you have nodejs 4.4 in addition to the version that was already installed and you can just use the nodecommand to reach the newly installed version:

现在除了已经安装的版本之外,你还有 nodejs 4.4,你可以使用node命令来访问新安装的版本:

$ node -v    // The new version added by nvm.
v4.4.5
$ nodejs -v  // The OS version is untouched and still available.
v0.10.25

You can install more nodejs versions and easily switch between them:

您可以安装更多的 nodejs 版本并在它们之间轻松切换:

$ nvm install 6.2
$ nvm use 6.2
Now using node v6.2.1 (npm v3.9.3)
$ node -v
v6.2.1
$ nvm use 4.4
Now using node v4.4.5 (npm v2.15.5)

回答by Phill

I am new to all this, but for me a simple alias worked:

我对这一切都很陌生,但对我来说,一个简单的别名有效:

alias node='env NODE_NO_READLINE=1 rlwrap nodejs'

at least for running things directly in bash and executing .js files.

至少可以直接在 bash 中运行并执行 .js 文件。

回答by cchamberlain

How about using the official instructions from the nodejs site:

如何使用来自nodejs 站点的官方说明

For v7:

对于 v7:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

For v6:

对于 v6:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

For v4:

对于 v4:

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

I've tested these from Windows bash (via subsystem for Linux - 14.04) and raspbian (ARM Debian based). Running sudo apt-get install -y nodejswithout first running the setup script will result in you getting node 0.10.

我已经从 Windows bash(通过 Linux 子系统 - 14.04)和 raspbian(基于 ARM Debian)测试了这些。在sudo apt-get install -y nodejs没有先运行安装脚本的情况下运行将导致您获得节点 0.10。

If you are planning on installing native npm modules requiring build, also run:

如果您计划安装需要构建的本机 npm 模块,还可以运行:

sudo apt install -y build-essential

Note: this is the recommended path for any Debian based distro across all architectures.

注意:这是所有架构中任何基于 Debian 的发行版的推荐路径。

回答by kfblake

Adding to @randunel's correct answer (can't yet comment on SO):

添加到@randunel 的正确答案(尚不能评论 SO):

I also had to symlink /usr/local/bin/node to /usr/bin/nodejs as well.

我还必须将 /usr/local/bin/node 符号链接到 /usr/bin/nodejs 。

sudo ln -s /usr/bin/nodejs /usr/local/bin/node

Apparently, this was overriding the /usr/bin/ node command.

显然,这覆盖了 /usr/bin/ node 命令。

No idea how that got set, but hope it helps someone else as it was a pain to figure out why the above wasn't working for me.

不知道这是如何设置的,但希望它可以帮助其他人,因为弄清楚为什么上述方法对我不起作用很痛苦。

回答by Erresen

Late answer, but for up-to-date info...

迟到的答案,但要了解最新信息...

If you install node.js using the recommend method from the node github installation readme, it suggests following the instructions on the nodesource blog article, rather than installing from the out of date apt-get repo, node.js should run using the nodecommand, as well as the nodejscommand, without having to make a new symlink.

如果您使用node github 安装自述文件中的推荐方法安装 node.js ,则建议按照nodesource 博客文章中的说明进行安装,而不是从过时的 apt-get repo 安装,node.js 应使用以下node命令运行,以及nodejs命令,而无需创建新的符号链接。

This method from article is:

文章中的这种方法是:

# Note the new setup script name for Node.js v0.12
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -

# Then install with:
sudo apt-get install -y nodejs

Note that this is for v0.12, which will get likely become outdated in the not to distant future.

请注意,这是针对 v0.12 的,在不久的将来可能会过时。

Also, if you're behind a corporate proxy (like me) you'll want to add the -E option to the sudo command, to preserve the env vars required for the proxy:

此外,如果您使用公司代理(像我一样),您需要在 sudo 命令中添加 -E 选项,以保留代理所需的环境变量:

curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -

curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -