node.js env: node: mac 中没有这样的文件或目录

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

env: node: No such file or directory in mac

node.jshomebrew

提问by user3818576

I'm searching it in google on how to show the version of node js or how I'm gonna work with npm? If I do this

我正在 google 中搜索它如何显示 node js 的版本或者我将如何使用 npm?如果我这样做

npm -v

even I already install it using brew install node. The result is always

即使我已经使用brew install node. 结果总是

env: node: No such file or directory

I already do a lot of command to solve for it, but failed. these are the command that I already try:

我已经做了很多命令来解决它,但失败了。这些是我已经尝试过的命令:

sudo apt-get install nodejs-legacy
sudo ln -s /usr/local/bin/node /usr/bin/node
brew unlink node
brew link node

I can't start the task because of this. help me guys. This work before after I used this command brew link --overwrite node. Now I have problem, i cant work anymore with npm. I'm really new about this. I don't have any idea now on how to fix this.

因此我无法开始任务。帮帮我吧伙计们。在我使用这个命令之前,这项工作brew link --overwrite node。现在我有问题,我不能再使用 npm 了。我真的很新。我现在不知道如何解决这个问题。

Update

更新

I already get the list using npm listcommand. I also get the idea here linkbut when I npm installinside the project. I alwayst get this "result env: node: No such file or directory",even I command npm -vbut If i command it outside my project. It work the npm -v

我已经使用npm list命令获取了列表。我也在这里得到了这个链接的想法,但是当我npm install进入项目时。我总是得到这个“结果环境:节点:没有这样的文件或目录”,即使我命令npm -v但如果我在我的项目之外命令它。它工作 npm -v

回答by jozh

I solved it this way:

我是这样解决的:

$ brew uninstall --force node
$ brew uninstall --force npm

after it

之后

$ brew install node

which suggested me to overwrite simlinks

这建议我覆盖 simlinks

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
  rm '/usr/local/share/doc/node/gdbinit'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

after executing

执行后

$ brew link --overwrite node

everything worked again.

一切都恢复了。

回答by King Reload

NOTE: Only mac users!

注意:仅限 mac 用户!

  1. uninstall node completely with the commands
  1. 使用命令完全卸载节点
curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh

Or you could check out this website: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

或者您可以查看此网站:如何完全卸载 Node.js,并从头重新安装 (Mac OS X)

if this doesn't work, you need to remove node via control panel or any other method. As long as it gets removed.

如果这不起作用,您需要通过控制面板或任何其他方法删除节点。只要能去掉。

  1. Install node via this website: https://nodejs.org/en/download/
  1. 通过这个网站安装节点:https: //nodejs.org/en/download/

If you use nvm, you can use:

如果使用nvm,则可以使用:

nvm install node

nvm install node

You can already check if it works, then you don't need to take the following steps with: npm -vand then node -v

您已经可以检查它是否有效,那么您不需要执行以下步骤:npm -v然后node -v

if you have nvminstalled: command -v nvm

如果您已nvm安装: command -v nvm

  1. Uninstall npm using the following command:
  1. 使用以下命令卸载 npm:

sudo npm uninstall npm -g

sudo npm uninstall npm -g

Or, if that fails, get the npm source code, and do:

或者,如果失败,请获取 npm 源代码,然后执行以下操作:

sudo make uninstall

sudo make uninstall

If you have nvminstalled, then use: nvm uninstall npm

如果已nvm安装,请使用:nvm uninstall npm

  1. Install npm using the following command: npm install -g grunt
  1. 使用以下命令安装 npm: npm install -g grunt

回答by RAM237

I was getting this env: node: No such file or directoryerror when running the job through Jenkins.

env: node: No such file or directory通过 Jenkins 运行作业时出现此错误。

What I did to fix it - added export PATH="$PATH:"/usr/local/bin/at the beginning of the script that Jenkins job executes.

我做了什么来修复它 -export PATH="$PATH:"/usr/local/bin/在 Jenkins 作业执行的脚本的开头添加。

回答by David

I got such a problem after I upgraded my node version with brew. To fix the problem

我用brew升级我的节点版本后遇到了这样的问题。解决问题

1)run $brew doctorto check out if it is successfully installed or not 2) In case you missed clearing any node-related file before, such error log might pop up:

1) 运行$brew doctor检查是否安装成功 2) 如果您之前没有清除任何与节点相关的文件,可能会弹出这样的错误日志:

Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. node

Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. node

3) Now you are recommended to run brew link command to delete the original node-related files and overwrite new files - $ brew link node.

3) 现在建议您运行 brew link 命令删除原有节点相关文件并覆盖新文件 - $ brew link node.

And that's it - everything works again !!!

就是这样 - 一切又正常了!!!

回答by H. Almidan

I re-installed node through this linkand it fixed it.

我通过此链接重新安装了节点并修复了它。

I think the issue was that I somehow got node to be in my /usr/bininstead of /usr/local/bin.

我认为问题在于我以某种方式让节点在我的/usr/bin而不是/usr/local/bin.

回答by Hola Soy Edu Feliz Navidad

Let's see, I sorted that on a different way. in my case I had as path something like ~/.local/binwhich seems that it is not the way it wants.

让我们看看,我以不同的方式对其进行了排序。在我的情况下,我有类似的路径~/.local/bin,这似乎不是它想要的方式。

Try to use the full path, like /Users/tobias/.local/bin, I mean, change the PATHvariable from ~/.local/binto /Users/tobias/.local/binor $HOME/.local/bin.

尝试使用完整路径,例如/Users/tobias/.local/bin,我的意思是,将PATH变量从更改~/.local/bin/Users/tobias/.local/bin$HOME/.local/bin

Now it works.

现在它起作用了。