【/usr/bin/env: node: No such file or directory】 的解决办法

  • 2022-07-15 22:24:12

今早突然想升级下 npm,在 ubuntu (windows 10 子系统)下,输入了如下的命令:

$ sudo npm install npm -g
/usr/bin/env: ‘node’: No such file or directory

没成功,错误提示:/usr/bin/env: ‘node’: No such file or directory,
找到了 https://github.com/nodejs/node-v0.x-archive/issues/3911


I've found this is often a misnaming error, if you install from a package manager you bin may be called nodejs so you just need to symlink it like so ln -s /usr/bin/nodejs /usr/bin/node

Just do
$ sudo apt-get install nodejs-legacy

也有人把原因给发出来了,有兴趣八卦可以读一读,是关于 Debian 社区和 Node 社区之间的事儿:

@houmie (and everyone who comes across this bug in the future)
These explain why:
http://debian.2.n7.nabble.com/Node-js-and-it-s-future-in-debian-td1042211.html (only read this last thread if you're a masochist)
As a Node developer, I would think hard before using Debian's packaged version of node, and would use Ubuntu with chrislea's PPA for Node or Debian stable with Node built from source in preference to the stock Debian nodejs package for the foreseeable future. The discussion on this bug makes clear that Debian has a very different idea of the role of Node in the wider world than most of the Node community.