[英]Express.js: No Such file or directory
I installed node with apt-get install nodejs
.我用
apt-get install nodejs
安装了节点。 Then I installed npm with apt-get install npm
.然后我用
apt-get install npm
。 Now when I try to run express
I get现在当我尝试运行
express
我得到
$ express
/usr/bin/env: node: No such file or directory
How do I resolve this error?如何解决此错误?
There are two package in Ubuntu that have similar names, node and nodejs . Ubuntu 中有两个名称相似的包, node和nodejs 。
node
does this, node
这样做,
Description-en: Amateur Packet Radio Node program.
说明-en:业余分组无线电节点程序。 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.
节点程序接受 TCP/IP 和分组无线电网络连接,并为用户提供一个界面,允许他们使用各种业余无线电协议与远程主机建立网关连接。
nodejs
does 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.
描述-zh:Node.js 基于事件的服务器端 javascript 引擎 Node.js 在设计上类似于 Ruby 的 Event Machine 或 Python 的 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.
Node.js 捆绑了几个有用的库来处理服务器任务:系统、事件、标准 I/O、模块、计时器、子进程、POSIX、HTTP、多部分解析、TCP、DNS、断言、路径、URL、查询字符串。
Fedora also follows a similar package naming scheme. Fedora 也遵循类似的包命名方案。 Because of this, the binary in
nodejs
had to be renamed to nodejs
from the original node
.因此,必须将
nodejs
的二进制文件从原始node
重命名为nodejs
。 However, this isn't technically kosher: and most nodejs programs (and libraries installed with npm) assume that the node binary is node
.然而,这在技术上并不符合:大多数 nodejs 程序(和使用 npm 安装的库)都假设 node 二进制文件是
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
node
package which handles the Amateur Packet Radio stuff.如果你走这条路,不要安装处理业余分组无线电内容的
node
包。
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
Alternatively, in the case of node, I'd suggest using n
and not installing node
.或者,在 node 的情况下,我建议使用
n
而不是安装node
。 Just install npm (which will install node), then remove npm, then tell apt to clean it up.只需安装 npm(将安装 node),然后删除 npm,然后告诉 apt 清理它。 To do this, simply run
为此,只需运行
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 nvm
but I personally prefer n
.还有其他二进制发行版管理器甚至可以从像
nvm
这样的 shell 脚本工作,但我个人更喜欢n
。 Think of n
like an apt for just one thing: the node binary which it installs to /usr/local/bin
.将
n
视为仅用于一件事的 apt:它安装到/usr/local/bin
的节点二进制文件。
Why are removing npm?为什么要删除 npm? We're not.
不是。
apt-get --purge remove
can only ever remove things installed by the package manager. apt-get --purge remove
只能删除包管理器安装的东西。 n latest
works outside of the package manager. n latest
包管理器之外的n latest
作品。 There are two npms if you do this,如果你这样做,有两个 npm,
apt-get
.apt-get
安装的版本。n latest
. 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.
而且,更糟糕的是,如果该版本有效,它可能会安装到不同的位置,并在其中进行 Debian 修改,假设 Debian 安装目录。 It's better to use either/or but not both.
最好使用其中之一/或但不要同时使用。
你应该安装 nodejs-legacy 包,它有一个从 /usr/bin/node 到 /usr/bin/nodejs 的链接
$ sudo apt-get install nodejs-legacy
就我而言,这是因为在我的PATH
环境变量中,我有“~/progs/node/bin/”,而“~”似乎没有被env
解析......用真正的完整路径替换它(“/ home/myuser/node/bin") 解决了我的问题。
This solution这个解决方案
export PATH="$HOME/opt/nodejs/bin:$PATH"
resolved this issue for me (it should work assuming the $HOME variable is set properly).为我解决了这个问题(假设 $HOME 变量设置正确,它应该可以工作)。 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)
它还允许我避免对我的主目录的路径进行硬编码(例如,如果需要,我可以使用不同的帐户/服务器重用我的 .bash_profile)
do this in cmd在 cmd 中执行此操作
sudo apt-get install nodejs-legacy
chmod your folder 700 (optional)
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
.注意:在远程服务器中,如果您可以运行 node 命令,但通过部署工具(如 shipit server)抛出
/usr/bin/env: 'node': No such file or directory
。 Creating symlink will resolve errors.创建符号链接将解决错误。
sudo ln -s $(which node) /usr/bin/node
sudo ln -s $(which npm) /usr/bin/npm
sudo ln -s $(which pm2) /usr/bin/pm2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.