简体   繁体   English

-bash:/ usr / local / bin / rbenv:/ usr / bin / env:错误的解释器:每次我尝试使用npm时,都会显示拒绝权限

[英]-bash: /usr/local/bin/rbenv: /usr/bin/env: bad interpreter: Permission denied shows up everytime I try to use npm

Everytime I try to use npm I get the error above. 每次我尝试使用npm时,都会收到上述错误。 Python works fine on my computer but npm and node never work. Python在我的计算机上工作正常,但是npm和node永远无法工作。

The error message you're getting suggests that executable script /usr/local/bin/rbenv has a shebang line specifying executable /usr/bin/env ( #!/usr/bin/env ... ). 您收到的错误消息表明, 可执行脚本/usr/local/bin/rbenv有一个shebang行,指定可执行文件/usr/bin/env#!/usr/bin/env ... )。

The fact that it says Permission denied means that, for some reason, /usr/bin/env is not executable , or at least not executable by you . 它说Permission denied的事实意味着,由于某种原因, /usr/bin/env不可执行的 ,或者至少不是您可执行的

This is highly unusual , because /usr/bin/env is a frequently used standard utility. 这是非常不寻常的 ,因为/usr/bin/env是经常使用的标准实用程序。 I would start investigating there, such as by running ls -l /usr/bin/env to see the permissions. 我将从那里开始调查,例如通过运行ls -l /usr/bin/env来查看权限。

More broadly, the question is why rbenv - a utility for managing multiple Ruby environments - is involved here at all . 更广泛地说, 问题是为什么在这里完全涉及rbenv一种用于管理多个Ruby环境的实用程序

I suggest deactivating it at least temporarily while troubleshooting - comment out the line that loads rbenv in your shell's profile/initialization file (in Bash: ~/.bash_profile or ~/.bashrc - see https://github.com/sstephenson/rbenv#how-rbenv-hooks-into-your-shell ), then open a new terminal window. 建议至少在故障排除时暂时将其停用 -注释掉在外壳程序的配置文件/初始化文件中加载rbenv的行(在Bash中: ~/.bash_profile~/.bashrc请参见https://github.com/sstephenson/rbenv #how-rbenv-hooks-into-your-shell ),然后打开一个新的终端窗口。

Finally, some background info on how npm is normally launched on a Unix system: 最后,一些有关如何在Unix系统上正常启动npm背景信息

  • npm is a symlink located in your $PATH that points to an executable script named npm-cli.js . npm是位于$PATH中的符号链接,指向名为npm-cli.js的可执行脚本。
  • npm-cli.js , despite containing JavaScript, actually uses #!/bin/sh as its shebang line, which means that the shell ( sh ) initially executes the file. npm-cli.js尽管包含JavaScript,但实际上使用#!/bin/sh作为其shebang行,这意味着shellsh最初将执行该文件。
  • The 2nd line in npm-cli.js is in fact the only line that sh executes: 实际上, npm-cli.js的第二行是sh执行的唯一行:
    • // 2>/dev/null; exec "`dirname "$0"`/node" "$0" "$@"
    • The line starts with // so that node later ignores it (since, in JavaScript, it is a comment ), given that the line's sole purpose is to invoke node . 该行以//开头,因此节点以后将忽略它(因为在JavaScript中,它是一个注释 ),因为该行的唯一目的是调用node
    • From the shell 's perspective, // is an attempt to run // as a command , which invariably fails, so 2>/dev/null is appended to suppress the error message. shell的角度来看, //是作为命令运行//的尝试,它总是失败,因此附加了2>/dev/null来抑制错误消息。
    • exec "`dirname "$0"`/node" "$0" "$@" then effectively relays invocation of the script at hand to the node executable: exec "`dirname "$0"`/node" "$0" "$@"然后将当前脚本的调用有效地传递给node可执行文件:
      • exec replaces the running sh instance with the command specified. exec用指定的命令替换正在运行的sh实例。
      • "`dirname "$0"`/node"` specifies the node executable as residing in the same directory as the the npm symlink (which makes sense, given that both node and npm are always installed in the same directory). "`dirname "$0"`/node"`节点可执行文件指定为与npm 符号链接位于同一目录中(考虑到nodenpm始终安装在同一目录中,这是有意义的)。
      • $0 refers to the script itself (the npm symlink) $0引用脚本本身( npm符号链接)
      • "$@" simply passes all arguments passed to npm through. "$@"只是将传递给npm所有参数传递npm
  • My guess is that the reason for this indirect invocation is to ensure that the node executable that is used to execute the npm script is from the same Node.js version. 我的猜测是,这种间接调用的原因是要确保用于执行npm脚本的node可执行文件来自同一 Node.js版本。 If a simple #!/usr/bin/env node shebang were used, then whatever node executable comes first in the $PATH would be used. 如果使用简单的#!/usr/bin/env node shebang,则将使用$PATH 第一个出现的node可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 /usr/bin/env: “node”: 权限被拒绝 - /usr/bin/env: “node”: Permission denied /usr/bin/env 'node' 权限被拒绝 - /usr/bin/env 'node' Permission Denied /usr/bin/env: 节点:权限被拒绝 - /usr/bin/env: node: Permission denied Node.js bash:/ usr / local / bin / node:权限被拒绝 - Node.js bash: /usr/local/bin/node: Permission denied -bash: /usr/local/bin/npm: 没有那个文件或目录 - -bash: /usr/local/bin/npm: No such file or directory bash:/usr/bin/express:/usr/bin/nodejs:错误的解释器:没有这样的文件或目录 - bash: /usr/bin/express: /usr/bin/nodejs: bad interpreter: No such file or directory 获取错误 /usr/bin/env: node : Permission Denied - Getting Error /usr/bin/env: node : Permission Denied EACCES:权限被拒绝,打开'/usr/local/lib/node_modules/npm/bin/npm-cli.js' - EACCES: permission denied, open '/usr/local/lib/node_modules/npm/bin/npm-cli.js' 在 WSL Ubuntu 20.04 上安装 npm 后,我收到消息“/usr/bin/env: 'bash\r': No such file or directory” - After installing npm on WSL Ubuntu 20.04 I get the message "/usr/bin/env: ‘bash\r’: No such file or directory" /usr/bin/env: 节点:使用 Symfony 6 “Encore”工具的 Docker 容器中的权限被拒绝 - /usr/bin/env: node: Permission denied in Docker container using Symfony 6 "Encore" tool
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM