node.js NPM:没有这样的文件或目录

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

NPM: no such file or directory

node.jsubuntunpm

提问by Nikita Yunoshev

I'm using Ubuntu 16.04 I removed NPM in order to install older version. (I can't exactly command which I used). now I can't install it again. npm -voutput: bash: /usr/bin/npm: /usr/bin/nodejs: bad interpreter: No such file or directorywhich npmoutput: /usr/bin/npm

我正在使用 Ubuntu 16.04 我删除了 NPM 以安装旧版本。(我不能完全命令我使用的)。现在我无法再次安装它。 npm -v输出:bash: /usr/bin/npm: /usr/bin/nodejs: bad interpreter: No such file or directorywhich npm输出:/usr/bin/npm

curl -L http://npmjs.org/install.sh | sudo sh

curl -L http://npmjs.org/install.sh | sudo sh

Output:

输出:

`install npm@latest
 fetching: https://registry.npmjs.org/npm/-/npm-5.5.1.tgz
 module.js:544
    throw err;
    ^

Error: Cannot find module '/tmp/npm.9881/package/bin/read-package-json.js'
at Function.Module._resolveFilename (module.js:542:15)
at Function.Module._load (module.js:472:25)
at Function.Module.runMain (module.js:682:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:613:3
up to date in 0.059s
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
+ [email protected]
added 1 package in 1.907s
 It worked`

UPD: Solved. Remove node/nodejs/npm completely and remove all relative folders a then reinstall via NVM helped. https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps

UPD:解决了。完全删除 node/nodejs/npm 并删除所有相关文件夹,然后通过 NVM 重新安装有帮助。 https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps

采纳答案by Osman Goni Nahid

Better way to install nodejs is via nvm. Here you can install/use multiple version of nodejs in a machine.

安装 nodejs 的更好方法是通过 nvm。在这里,您可以在一台机器上安装/使用多个版本的 nodejs。

https://github.com/creationix/nvm

https://github.com/creationix/nvm

then

然后

nvm install $vesionNo

nvm use $versionNO

// for default 

nvm alias default node

回答by Víctor López

In some Linux distributions, node is installed on /usr/bin/nodejsand not on /usr/bin/node.

在某些 Linux 发行版中,node 安装/usr/bin/nodejs/usr/bin/node.

What I did, is install nodejs-legacy, and it solved the problem. It creates a symlink from /usr/bin/nodejsto /usr/bin/node.

我所做的是安装 nodejs-legacy,它解决了问题。它创建了一个从/usr/bin/nodejs到的符号链接/usr/bin/node

So, what I recommend (as the easiest solution) is to install nodejs-legacy:

所以,我推荐的(作为最简单的解决方案)是安装nodejs-legacy

sudo apt-get install nodejs-legacy

回答by ?smail DEN?Z

If there is a character or a space other than the English characters from the windows user name, it can also be caused by this.

如果windows用户名中有英文字符以外的字符或空格,也可能是这个原因。

I'm talking about the installation of global packages. If you are installing a package on a specific project, it may also be caused by the lack of package.json.

我说的是全局包的安装。如果是在特定项目上安装包,也可能是缺少 package.json 导致的。

回答by HOTAM SINGH

Try this command:

试试这个命令:

sudo npm install -g npm@latest

For latest version or otherwise:

对于最新版本或其他版本:

sudo npm install -g npm@<version_no_here>

For specific version.

对于特定版本。