Linux重启后nodejs消失了

2023-12-31

我刚刚使用 nvm 安装了 nodejs 版本 0.10.14,它安装成功。 同样在安装nodejs之前,我安装了zeromq版本2.2.0。

出于测试目的,我尝试运行下面的基本酒吧示例。

var zmq = require('zmq');
var socket = zmq.socket('pub');

console.log("Binding socket on port 8800...");

socket.bind('tcp://localhost:8800', function(err){
    if(err){
        console.log(err)
    } else{
        console.log("listening on port 8800");
    }
});
socket.send("hello this is testServer2 on port 8800...");

但它抛出了错误 -

events.js:72
    throw er; // Unhandled 'error' event
          ^
TypeError: Socket is busy
    at Socket._ioevents (/home/zishan/node_modules/zmq/lib/index.js:198:22)
    at Socket._flush (/home/zishan/node_modules/zmq/lib/index.js:343:23)
    at Socket.send (/home/zishan/node_modules/zmq/lib/index.js:318:42)
    at Object.<anonymous> (/home/zishan/newsURLCollector/testServer2.js:16:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

端口 8800 已使用 ufw 打开。

我尝试用谷歌搜索套接字繁忙错误,但没有运气,比我想象的重新启动 Ubuntu 更好,问题变得更糟。当我重新登录并尝试再次运行上面的示例时,系统会抛出以下消息:

zishan@news01:~/newsURLCollector$ node testServer2.js

The program 'node' can be found in the following packages:
 * node
 * nodejs-legacy
Try: sudo apt-get install <selected package>

到底为什么工作节点停止工作并且无法找到节点。然后我按照系统提示做了sudo apt-get 安装节点下面是结果:

zishan@news01:~$ sudo apt-get install node
[sudo] password for zishan:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libpgm-5.1-0
Use 'apt-get autoremove' to remove it.
The following NEW packages will be installed
  node
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 0 B/1,284 B of archives.
After this operation, 38.9 kB of additional disk space will be used.
Selecting previously unselected package node.
(Reading database ... 66172 files and directories currently installed.)
Unpacking node (from .../node_0.3.2-7.4_all.deb) ...
Processing triggers for man-db ...
Setting up node (0.3.2-7.4) ...
zishan@news01:~$ node -v

然后我尝试查找节点版本,但什么也没发生,我现在没有收到节点提示,但是当我执行“哪个节点”时,它说 - /usr/sbin/node

重启后不知道出了什么问题。任何人都可以解释一下吗?


当 NVM 加载时,它会加载当前标记为的任何 Node 版本default.

nvm install v0.10.14将会安装v0.10.14并通过键入告诉 NVM 使其可供您使用node在您当前的终端中,但它不会将其标记为默认终端,因为您可以轻松安装 5 个版本的节点。 NVM 也不会做任何花哨的事情,比如记住您上次使用的 Node 版本,因为也许您打开了 10 个终端,每个终端都有不同的版本。

你所需要做的就是运行nvm use v0.10.14告诉你给定的终端公开v0.10.14 as node.

对于您的情况,最好的办法可能是将其设置为默认值,因此它将在每次重新启动和新终端时使用它:

nvm alias default v0.10.14

正如您已经想到的,通过运行

apt-get install node

你安装了这个:http://packages.qa.debian.org/n/node.html http://packages.qa.debian.org/n/node.html

我现在也推荐你apt-get remove nodejs并坚持nvm. The deb软件包很快就会过时,使用 NVM 可以让您更轻松地跟上。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux重启后nodejs消失了 的相关文章

随机推荐