Express.js:没有这样的文件或目录 [英] Express.js: No Such file or directory

查看:30
本文介绍了Express.js:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 apt-get install nodejs 安装了节点.然后我用 apt-get install npm 安装了 npm.现在当我尝试运行 express 我得到

I installed node with apt-get install nodejs. Then I installed npm with apt-get install npm. Now when I try to run express I get

$ express 
/usr/bin/env: node: No such file or directory

我该如何解决这个错误?

How do I resolve this error?

推荐答案

Ubuntu 中有两个名称相似的包,nodenodejs.

There are two package in Ubuntu that have similar names, node and nodejs.

node 这样做,

Description-en:业余分组无线电节点程序.节点程序接受 TCP/IP 和分组无线电网络连接,并为用户提供一个界面,允许他们使用各种业余无线电协议与远程主机建立网关连接.

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.

nodejs 这样做,

Description-en:Node.js 基于事件的服务器端 javascript 引擎 Node.js 在设计上类似于 Ruby 的 Event Machine 或 Python 的 Twisted 等系统,并受其影响.它将事件模型更进一步——它将事件循环呈现为一种语言结构而不是一个库.Node.js 捆绑了几个有用的库来处理服务器任务:系统、事件、标准 I/O、模块、计时器、子进程、POSIX、HTTP、多部分解析、TCP、DNS、断言、路径、URL、查询字符串.

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.

Fedora 也遵循类似的包命名方案.因此,nodejs 中的二进制文件必须从原始 node 重命名为 nodejs.然而,这在技术上并不符合标准:大多数 nodejs 程序(以及与 npm 一起安装的库)都假定 node 二进制文件是 node.如果你想解决这个问题,最简单的方法就是将两者符号链接在一起.如果您采用这条路线,请不要安装处理业余分组无线电内容的 node 包.

Fedora also follows a similar package naming scheme. Because of this, the binary in nodejs had to be renamed to nodejs from 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 node package which handles the Amateur Packet Radio stuff.

sudo ln -s /usr/bin/nodejs /usr/local/bin/node

或者,对于节点,我建议使用 n 而不是安装 node.只需安装 npm(将安装 node),然后删除 npm,然后告诉 apt 清理它.为此,只需运行

Alternatively, in the case of node, I'd suggest using n and 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

sudo apt-get install npm
sudo npm install -g n
sudo n latest
sudo apt-get --purge remove npm
sudo apt-get autoremove

还有其他二进制发行版管理器甚至可以使用 nvm 这样的 shell 脚本,但我个人更喜欢 n.把 n 想象成一个适合做一件事的工具:它安装到 /usr/local/bin 的节点二进制文件.

There are other binary distro managers that even work from a shell script like nvm but I personally prefer n. Think of n like an apt for just one thing: the node binary which it installs to /usr/local/bin.

为什么要删除 npm?不是.apt-get --purge remove 可以删除包管理器安装的东西.n latest 在包管理器之外工作.如果你这样做,有两个 npm,

Why are removing npm? We're not. apt-get --purge remove can only ever remove things installed by the package manager. n latest works outside of the package manager. There are two npms if you do this,

  1. 发行版 (Debian/Ubuntu) 使用 apt-get 安装的版本.
  2. n个最新安装的版本.
  1. version installed by the distro (Debian/Ubuntu) using apt-get.
  2. version installed by n latest.

拥有发行版的旧版本毫无意义.而且,更糟糕的是,如果该版本有效,它可能会安装到不同的位置,并在其中进行 Debian 修改,假设 Debian 安装目录.最好使用其中一个/或但不要同时使用.

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.

这篇关于Express.js:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆