【问题标题】:Nodejs or node returns nothing on UbuntuNodejs 或 node 在 Ubuntu 上不返回任何内容
【发布时间】:2017-10-17 03:13:29
【问题描述】:

我已经在我的 MacOS 环境中构建了一个在 Node 上运行的 Javascript 应用程序,并且一切正常。现在我已经创建了一个 Azure Ubuntu 服务器,并从我的机器中同步了源代码。

我通过安装 npm、node 和所有必需的包来复制应用程序要求。我通过 SSH 连接到服务器,当我从 Ubuntu 服务器运行应用程序时,通过

$node app.js

所有返回的是

$

读到 Ubuntu 使用 nodejs-legacy,我也尝试过

$nodejs app.js

同样的结果

$node -v
v4.7.2

我还构建了一个 package.json 文件,并在使用

执行时
npm start

它立即返回到 $。

【问题讨论】:

  • 你是如何安装节点的?在像 Ubuntu 这样的基于 Debian 的发行版上,有一个名为 node 的业余无线电软件。所以如果你apt install node 它会安装一些完全不同的东西。你需要apt install nodejs nodejs-legacy npm
  • 是的,我就是这样安装的$ sudo apt install nodejs nodejs-legacy npm Reading package lists... Done Building dependency tree Reading state information... Done nodejs is already the newest version (4.7.2~dfsg-1ubuntu3). nodejs-legacy is already the newest version (4.7.2~dfsg-1ubuntu3). npm is already the newest version (3.5.2-0ubuntu4). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

标签: node.js azure ubuntu npm


【解决方案1】:

它不起作用的原因是在 Ubuntu 上安装 nodejs 时调用的默认 APT 存储库已过时。我运行以下代码来解决问题。它会自动卸载所有其他不正确的包,设置正确的存储库,然后重新安装。

# Sets up the correct APT repository hosted by NodeSource, and adds the PGP key to the system's APT keychain
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

# Installs Node.js
$ sudo apt-get install -y nodejs

# Updates NPM
$ sudo npm install npm --global

现在所有应用都按预期工作!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 2019-04-06
    相关资源
    最近更新 更多