NPM: no such file or directory

送分小仙女□ 提交于 2020-12-08 08:05:53

问题


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 -v output: bash: /usr/bin/npm: /usr/bin/nodejs: bad interpreter: No such file or directory which npm output: /usr/bin/npm

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
+ npm@5.5.1
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


回答1:


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

https://github.com/creationix/nvm

then

nvm install $vesionNo

nvm use $versionNO

// for default 

nvm alias default node



回答2:


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

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

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

sudo apt-get install nodejs-legacy



回答3:


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.

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.




回答4:


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.



来源:https://stackoverflow.com/questions/47592667/npm-no-such-file-or-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!