node.js Express.js:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14914715/
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
Express.js: No Such file or directory
提问by Evan Carroll
I installed node with apt-get install nodejs. Then I installed npm with apt-get install npm. Now when I try to run expressI get
我用apt-get install nodejs. 然后我用apt-get install npm. 现在,当我尝试跑步时,express我得到了
$ express
/usr/bin/env: node: No such file or directory
How do I resolve this error?
如何解决此错误?
回答by Evan Carroll
There are two package in Ubuntu that have similar names, nodeand nodejs.
Ubuntu 中有两个名称相似的包,node和nodejs。
nodedoes this,
node做这个,
Description-en: Amateur Packet Radio Node program. The node program accepts TCP/IP and packet radio network connections and presents users with an interface that allows them to make gateway connections to remote hosts using a variety of amateur radio protocols.
说明-en:业余分组无线电节点程序。节点程序接受 TCP/IP 和分组无线电网络连接,并为用户提供一个界面,允许他们使用各种业余无线电协议与远程主机建立网关连接。
nodejsdoes this,
nodejs做这个,
Description-en: Node.js event-based server-side javascript engine Node.js is similar in design to and influenced by systems like Ruby's Event Machine or Python's Twisted. It takes the event model a bit further - it presents the event loop as a language construct instead of as a library. Node.js is bundled with several useful libraries to handle server tasks : System, Events, Standard I/O, Modules, Timers, Child Processes, POSIX, HTTP, Multipart Parsing, TCP, DNS, Assert, Path, URL, Query Strings.
描述-zh:Node.js 基于事件的服务器端 javascript 引擎 Node.js 在设计上类似于 Ruby 的 Event Machine 或 Python 的 Twisted 等系统,并受其影响。它将事件模型更进一步——它将事件循环呈现为一种语言结构而不是一个库。Node.js 捆绑了几个有用的库来处理服务器任务:系统、事件、标准 I/O、模块、计时器、子进程、POSIX、HTTP、多部分解析、TCP、DNS、断言、路径、URL、查询字符串。
Fedora also follows a similar package naming scheme. Because of this, the binary in nodejshad to be renamed to nodejsfrom the original node. However, this isn't technically kosher: and most nodejs programs (and libraries installed with npm) assume that the node binary is node. If you want to get around this the easiest way is just symlink the two together. If you take this route, don't install the nodepackage which handles the Amateur Packet Radio stuff.
Fedora 也遵循类似的包命名方案。正因为如此,在二进制nodejs不得不被重新命名为nodejs从原来的node。然而,这在技术上并不符合:大多数 nodejs 程序(和使用 npm 安装的库)都假设 node 二进制文件是node. 如果你想解决这个问题,最简单的方法就是将两者符号链接在一起。如果您采用这条路线,请不要安装node处理业余分组无线电内容的软件包。
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
Alternatively, in the case of node, I'd suggest using nand not installing node. Just install npm (which will install node), then remove npm, then tell apt to clean it up. To do this, simply run
或者,在 node 的情况下,我建议使用n而不是安装node. 只需安装 npm(将安装 node),然后删除 npm,然后告诉 apt 清理它。为此,只需运行
sudo apt-get install npm
sudo npm install -g n
sudo n latest
sudo apt-get --purge remove npm
sudo apt-get autoremove
There are other binary distro managers that even work from a shell script like nvmbut I personally prefer n. Think of nlike an apt for just one thing: the node binary which it installs to /usr/local/bin.
还有其他二进制发行版管理器甚至可以使用 shell 脚本工作,nvm但我个人更喜欢n. 只考虑n一件事:它安装到的节点二进制文件/usr/local/bin。
Why are removing npm? We're not. apt-get --purge removecan onlyever remove things installed by the package manager. n latestworks outside of the package manager. There are two npms if you do this,
为什么要删除 npm?不是。apt-get --purge remove可仅过移除由包管理器安装的东西。n latest在包管理器之外工作。如果你这样做,有两个 npm,
- version installed by the distro (Debian/Ubuntu) using
apt-get. - version installed by
n latest.
- 发行版(Debian/Ubuntu)使用
apt-get. - 安装的版本
n latest。
No point in having the distro's older version. And, even worse, if that version works it can potentially install to a different location and have Debian modifications in it that assume Debian install directories. It's better to use either/or but not both.
拥有发行版的旧版本毫无意义。而且,更糟糕的是,如果该版本有效,它可能会安装到不同的位置,并在其中进行 Debian 修改,假设 Debian 安装目录。最好使用其中之一/或但不要同时使用。
回答by Sergey Fedoseev
you should install nodejs-legacy package which have a link from /usr/bin/node to /usr/bin/nodejs
你应该安装 nodejs-legacy 包,它有一个从 /usr/bin/node 到 /usr/bin/nodejs 的链接
$ sudo apt-get install nodejs-legacy
$ sudo apt-get install nodejs-legacy
回答by Anthony O.
In my case it was because in my PATHenvironment variable, I had "~/progs/node/bin/" and the "~" does not seem to be resolved by env... replacing it with the real full path ("/home/myuser/node/bin") solved my problem.
就我而言,这是因为在我的PATH环境变量中,我有“~/progs/node/bin/”,而“~”似乎没有通过env……用真正的完整路径(“/home/ myuser/node/bin") 解决了我的问题。
回答by SnapShot
This solution
这个解决方案
export PATH="$HOME/opt/nodejs/bin:$PATH"
resolved this issue for me (it should work assuming the $HOME variable is set properly). It also allows me to avoid hard coding the path to my home directory (for example so I can reuse my .bash_profile with different accounts/servers if I need to)
为我解决了这个问题(假设 $HOME 变量设置正确,它应该可以工作)。它还允许我避免对我的主目录的路径进行硬编码(例如,如果需要,我可以使用不同的帐户/服务器重用我的 .bash_profile)
回答by Amrit Shrestha
Disclaimer: only for bash command running via deployment tools
免责声明:仅适用于通过部署工具运行的 bash 命令
Note:In remote server, if you can run node command but via deployment tool like shipit server throws like /usr/bin/env: ‘node': No such file or directory. Creating symlink will resolve errors.
注意:在远程服务器中,如果您可以运行 node 命令,但是通过部署工具(如shipit server)抛出类似/usr/bin/env: ‘node': No such file or directory. 创建符号链接将解决错误。
sudo ln -s $(which node) /usr/bin/node
sudo ln -s $(which npm) /usr/bin/npm
sudo ln -s $(which pm2) /usr/bin/pm2
回答by Bilal Naqvi
do this in cmd
在 cmd 中执行此操作
sudo apt-get install nodejs-legacy
chmod your folder 700 (optional)

