无法安装 NodeJs: /usr/bin/env: node: No such file or directory

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

Cannot install NodeJs: /usr/bin/env: node: No such file or directory

node.jsubuntugruntjsnpm-installnode-modules

提问by Rosamunda

I'm trying to install nodeJs into my Ubuntu 14.04 in order to use GruntJs.

我正在尝试将 nodeJs 安装到我的 Ubuntu 14.04 中以使用 GruntJs。

I've read about Ubuntu different wayof doing it (issues?), so this is what I've done in order to install it:

我已经阅读了关于Ubuntu 不同的操作方式问题?),所以这是我为了安装它所做的:

sudo apt-get install npm

sudo npm install -g grunt-cli

Typing grunt after that I've got the error:

之后输入 grunt 出现错误:

/usr/bin/env: node: No such file or directory

So, I've tried:

所以,我试过:

curl -sL https://deb.nodesource.com/setup | sudo bash -

sudo apt-get install -y nodejs

sudo apt-get update

And trying again, and still getting the error, I've tried:

再试一次,仍然得到错误,我试过:

sudo add-apt-repository https://launchpad.net/~chris-lea/+archive/node.js/

sudo apt-get install -y nodejs

I've got this message:

我收到了这条消息:

nodejs is already the newest version.
0 to upgrade, 0 to newly install, 0 to remove and 3 not to upgrade.

I did try a cleanup just in case:

我确实尝试了清理以防万一:

sudo apt-get autoremove

But nope, the error is still there: when I type grunt I still get /usr/bin/env: node: No such file or directory

但是不,错误仍然存​​在:当我输入 grunt 时,我仍然得到 /usr/bin/env: node: No such file or directory

What should I do?

我该怎么办?

回答by Rosamunda

Doing a symlink solves the issue:

做一个符号链接解决了这个问题:

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

(My thanks and +1 vote to bodokaiser's answer).

(我的感谢和 +1 投票给bodokaiser 的回答)。

回答by Muhammad bin Yusrat

The issue is not with the version of node. Instead, it is the way NodeJS is installed by default in Ubuntu. When running a Node application in Ubuntu you have to run nodejs somethign.jsinstead of node something.js

问题不在于节点的版本。相反,这是默认情况下在 Ubuntu 中安装 NodeJS 的方式。在 Ubuntu 中运行 Node 应用程序时,您必须运行nodejs somethign.js而不是node something.js

So the application name called in the terminal is nodejsand not node. This is why there is a need for a symlink to simply forward all the commands received as nodeto nodejs.

所以在终端中调用的应用程序名称是nodejs而不是node。这就是为什么需要一个符号链接来简单地将接收node到的所有命令转发到nodejs.

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

回答by vanlan228

I think you should upgrade lastest node version

我认为您应该升级最新的节点版本

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

回答by Hiro

if you are able to access node on ubuntu terminal using nodejs command,then this problem can be simply solved using -creating a symbolic link of nodejs and node using

如果您能够使用 nodejs 命令访问 ubuntu 终端上的节点,那么可以使用 -create a symbol link of nodejs 和 node using 来简单地解决这个问题

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

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

and this may solve the problem

这可能会解决问题

回答by Suleyman Arslan

In my case, installing nodejs-legacysolved the issue.

就我而言,安装 nodejs-legacy解决了这个问题。

sudo apt-get install nodejs-legacy

回答by Prabhu Nandan Kumar

Just do

做就是了

$ sudo apt-get install nodejs-legacy

And it will start working.

它将开始工作。

回答by Ahmad Awais

I've found this is often a misnaming error, if you install from a package manager you bin may be called nodejs so you just need to symlink it like so

我发现这通常是一个命名错误,如果你从包管理器安装你的 bin 可能被称为 nodejs,所以你只需要像这样符号链接它

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

回答by Tom Hale

If you already have nodejs installed (check with which nodejs) and don't want to install another package, you can, as root:

如果您已经安装了 nodejs(检查which nodejs)并且不想安装另一个包,您可以以 root 身份:

update-alternatives --install /usr/bin/node node /usr/bin/nodejs 99

回答by Naveen Gupta

When I was using gulp i got this error.

当我使用 gulp 时,出现此错误。

~$ gulp

/usr/bin/env: ‘node': No such file or directory

/usr/bin/env: 'node': 没有那个文件或目录

This was removed by executing following command you have to keep in mind that /usr/bin directory has all permissions.

这是通过执行以下命令删除的,您必须记住 /usr/bin 目录具有所有权限。

~$ ln -s /usr/bin/nodejs /usr/bin/node

this works for me..

这对我有用..

回答by Pavel

There are two solutions to this:

对此有两种解决方案:

a) Set your PATH variable to include "/usr/local/bin"

a) 将 PATH 变量设置为包含“/usr/local/bin”

export PATH="$PATH:/usr/local/bin"

export PATH="$PATH:/usr/local/bin"

b) Create a symlink to "/usr/bin" which is already in your PATH

b) 创建一个指向“/usr/bin”的符号链接,它已经在你的 PATH 中

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

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

I hope it helps.

我希望它有帮助。