无法安装NodeJ:/ usr / bin / env:node:没有这样的文件或目录

时间:2014-10-12 01:17:45

标签: node.js ubuntu gruntjs npm-install node-modules

我试图将nodeJs安装到我的Ubuntu 14.04中以便使用GruntJs。

我已经阅读了Ubuntu different way这样做(issues?),所以这就是我为安装它而做的事情:

sudo apt-get install npm

sudo npm install -g grunt-cli

之后输入grunt我收到了错误:

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

所以,我试过了:

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

sudo apt-get install -y nodejs

sudo apt-get update

再试一次,仍然得到错误,我已经尝试过了:

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

sudo apt-get install -y nodejs

我收到了这条消息:

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

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

sudo apt-get autoremove

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

我该怎么办?

18 个答案:

答案 0 :(得分:782)

找到答案。为了防止有人帮助,我会在这里发布:

执行符号链接可解决此问题:ln -s /usr/bin/nodejs /usr/bin/node (我的感谢和+1投票给bodokaiser)。

注意:我认为这篇文章并不完全重复,因为该帖子有点像浏览器问题。

答案 1 :(得分:113)

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

因此终端中调用的应用程序名称为nodejs而不是node。这就是为什么需要一个符号链接,只需将收到的所有命令node转发给nodejs

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

答案 2 :(得分:49)

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

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

答案 3 :(得分:29)

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

Option Explicit Dim app ' As SASEGuide.Application Call dowork 'shut down the app If not (app Is Nothing) Then app.Quit Set app = Nothing End If Sub dowork() On Error Resume Next '---- ' Start up Enterprise Guide using the project name '---- Dim prjName ' As String Dim prjObject ' As SASEGuide.Project Dim containerName ' As String Dim containerObject ' As SASEGuide.Container Dim containerColl ' As SASEGuide.ContainerCollection dim orderedListObject ' as SASEguide.Container prjName = "\\pathtoproject\test project.egp" ' Project Name containerName = "My Ordered List" ' Name of the Ordered List Set app = CreateObject("SASEGObjectModel.Application.7.1") If Checkerror("CreateObject") = True Then Exit Sub End If Set prjObject = app.Open(prjName,"") If Checkerror("App.Open") = True Then Exit Sub End If '----- 'Get The Container Collection and Object '----- Set containerColl = prjObject.ContainerCollection If Checkerror("Project.ContainerCollection") = True Then Exit Sub End If Dim i ' As Long Dim j ' As Long Dim count ' As Long Dim count_OL ' as Long count = containerColl.count For i = 0 To count - 1 Set containerObject = containerColl.Item(i) If Checkerror("ContainerCollection.Item") = True Then Exit Sub End If If (containerObject.Name = "Ordered Lists") Then count_OL = containerObject.items.count For j = 0 to count_OL - 1 If Checkerror("ContainerCollection.Item") = True Then Exit Sub End If Set orderedListObject = containerObject.items.item(j) If (orderedListObject.name = containerName) then exit for Else Set orderedListObject = Nothing end if Next Exit For Else Set containerObject = Nothing Set orderedListObject = Nothing End If Next If not (orderedListObject is nothing) Then '---- ' Run the Container '---- orderedListObject.Run If Checkerror("Container.Run") = True Then Exit Sub End If Else wscript.echo "Not Found" End If '----- ' Save the new project '----- prjObject.Save If Checkerror("Project.Save") = True Then Exit Sub End If '----- ' Close the project '----- prjObject.Close If Checkerror("Project.Close") = True Then Exit Sub End If End Sub Function Checkerror(fnName) Checkerror = False Dim strmsg ' As String Dim errNum ' As Long If Err.Number <> 0 Then strmsg = "Error #" & Hex(Err.Number) & vbCrLf & "In Function " & fnName & vbCrLf & Err.Description MsgBox strmsg 'Uncomment this line if you want to be notified via MessageBox of Errors in the script. Checkerror = True End If End Function

and this may solve the problem

答案 4 :(得分:24)

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

sudo apt-get install nodejs-legacy

答案 5 :(得分:12)

如果您正在使用nvm节点版本管理器,请使用以下命令创建符号链接:

sudo ln -s "$(which node)" /usr/bin/node
sudo ln -s "$(which npm)" /usr/bin/npm
  • 第一个命令为node创建一个符号链接
  • 第二条命令为npm创建符号链接

答案 6 :(得分:10)

只做

$ sudo apt-get install nodejs-legacy

它将开始工作。

答案 7 :(得分:9)

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

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

答案 8 :(得分:7)

如果您已经安装了nodejs(请查看which nodejs)并且不想安装其他软件包,您可以以root身份进行:

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

答案 9 :(得分:6)

当我使用gulp时,我收到了这个错误。

~$ gulp

/ usr / bin / env:'node':没有这样的文件或目录

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

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

这对我有用..

答案 10 :(得分:4)

虽然ln -s是最明显最容易解决的问题,但有一点解释:

  

由于与另一个包冲突,可执行文件来自   Ubuntu存储库称为nodejs而不是node。保持这个   介意你正在运行软件。

安装sudo apt-get install nodejs时会出现此建议。

所以其他一些已知的工具(我不知道它的作用。虽然ubuntu存储库已知,但默认情况下在16.04中没有安装)占用该命名空间。

本来不错的,如果Ubuntu提供了如何解决这个'干净利落'的建议,如果不是通过手工做什么,否则包装会做。 (碰撞仍然是碰撞......如果+发生碰撞时)

答案 11 :(得分:4)

有两种解决方法:

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

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

b)创建指向您路径中已经存在的“ / usr / bin”的符号链接

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

希望对您有帮助。

答案 12 :(得分:2)

sudo PATH="$PATH:/usr/local/bin" npm install -g <package-name>

答案 13 :(得分:2)

根据您安装节点的方式,大部分时间它可能不在/ usr / bin /中,在我自己的情况下,我使用nvm进行安装,所以我的节点位于./nvm/versions.

使用此命令which node我找到了路径,但为了使工作更轻松,您可以运行此命令。

nodepath=$(which node); sudo ln -s $nodepath /usr/bin/node

以上命令将获取节点的位置并为您创建链接。

答案 14 :(得分:2)

按照以下命令解决问题,

步骤1.打开终端并输入,

sudo npm cache clean -f

此命令将清除整个NPM缓存

然后输入密码

第2步。

sudo npm install -g n

第3步。

sudo n stable 

使用此命令,您可以安装节点的最新稳定版本。

现在将安装最新版本的节点。您可以通过以下方式验证版本:

node -v

答案 15 :(得分:1)

对于我的案例链接 工作,如下所示

  

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

但是你可以以root身份打开/ usr / local / bin / lessc,并将第一行从node更改为nodejs。

  

- #!/ usr / bin / env node

     

+#!/ usr / bin / env nodejs

答案 16 :(得分:0)

只需通过此命令重命名命令或文件名ln -s /usr/bin/nodejs /usr/bin/node

答案 17 :(得分:0)

对我来说,已接受的答案尚未奏效。我按照这里的建议开始了:

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

完成此操作后,出现以下错误:

  

/usr/local/lib/node_modules/npm/bin/npm-cli.js:85         let notifier = require('update-notifier')({pkg})         ^^^

     

SyntaxError:范围限定的声明(let,const,函数,类)   严格模式外尚不支持       在exports.runInThisContext(vm.js:53:16)       在Module._compile(module.js:374:25)       在Object.Module._extensions..js(module.js:417:10)       在Module.load(module.js:344:32)       在Function.Module._load(module.js:301:12)       在Function.Module.runMain(module.js:442:10)       在启动时(node.js:136:18)       在node.js:966:3

解决方案是从https://nodejs.org/en/download/下载最新版本的node。

然后我做了:

sudo tar -xf node-v10.15.0-linux-x64.tar.xz --directory /usr/local --strip-components 1

现在更新终于成功了:npm -v从3.2.1更改为6.4.1

相关问题