linux重启后nodejs消失了 [英] nodejs gone after linux reboot

查看:28
本文介绍了linux重启后nodejs消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just installed nodejs version 0.10.14 using nvm it installed successfully. also before installing nodejs, I installed zeromq version 2.2.0.

出于测试目的,我试图在下面运行一个基本的 pub 示例.

For test purpose I was trying to run a basic pub example below.

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 打开了.

port 8800 is already opened using ufw.

我尝试在谷歌上搜索 socket busy 错误,但没有运气,我认为重新启动 Ubuntu 很好,但问题变得更糟.当我重新登录并尝试再次运行上面的示例时,系统抛出消息:

I tried googling the socket busy error but with no luck, than I thought it's good to reboot Ubuntu and the problem goes even worse. when I log back in and tries to run the above example again, system throws the message:

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 install node 下面是结果:

WHY on earth a working node stops working and is unable to find node. then I followed the system prompt and did sudo apt-get install node below is the result:

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

then i tried to find the node version but nothing is happening, I am not getting a node prompt now but when i did "which node" it says - /usr/sbin/node

我不知道重启后出了什么问题.谁能解释一下.

I do not know what is wrong after the reboot. Could any one please explain.

推荐答案

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

When NVM loads, it loads whatever version of Node is currently marked as default.

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

nvm install v0.10.14 will install v0.10.14 and tell NVM to make it available for you to use by typing node in your current terminal, but it does not mark it as default, since you could just as easily have installed 5 versions of node. NVM also does not do anything fancy like remember what version of Node you were using last, since maybe you have 10 terminals open with a different version in each one.

您需要做的就是运行 nvm use v0.10.14 告诉给定的终端将 v0.10.14 公开为 node.

All you need to do was run nvm use v0.10.14 to tell your given terminal to expose v0.10.14 as node.

在您的情况下,最好的办法可能是将其设置为默认值,这样它就会在每次重新启动和新终端时使用它:

In your case, the best thing to do would probably be to set it as the default, so it will use it on every restart and new terminal:

nvm alias default v0.10.14

正如你已经发现的,通过运行

As you figured out already, by running

apt-get install node

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

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

I would recommend you also now apt-get remove nodejs and stick with nvm. The deb packages get out-of-date fairly rapidly and using NVM will allow you to keep up much more easily.

这篇关于linux重启后nodejs消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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