nodejs gone after linux reboot

我是研究僧i 提交于 2019-12-10 13:43:57

问题


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

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...");

but it was throwing error -

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)

port 8800 is already opened using ufw.

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>

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

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.


回答1:


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

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.

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

you installed this: http://packages.qa.debian.org/n/node.html

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.




回答2:


After long struggle it is working now, I used below link to remove and then install node again using apt-get. but the only thing new I used now is removing node using purge switch.

https://askubuntu.com/questions/235655/node-js-conflicts-sbin-node-vs-usr-bin-node

below i used from above link:

sudo apt-get --purge remove node sudo apt-get --purge remove nodejs sudo apt-get install nodejs

Now nodejs is working fine and zmq as well. I think it's the purge command which does the job as previously I was building from the source tar and removing manually as apt-get alone was not working!

Note for others - not all version of nodejs is compatible with zmq, one which I am using is Nodejs - 0.10.24 zeromq - 2.2.0




回答3:


Basically the package installed on your machine was called 'nodejs' instead of 'node'. So your command needed to be changed to:

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

the package 'node' in ubuntu has already been taken by Amateur Packet Radio "Node" Program, so when node came along to ubuntu apt packages, it was renamed to nodejs.



来源:https://stackoverflow.com/questions/20921427/nodejs-gone-after-linux-reboot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!