1

I use PM2 to run my node processes in production (on Ubuntu 14.04). After upgrading from node 0.12.x to nodejs 4.4.x, the command to run node(js) changed from node to nodejs. I followed the instructions on the nodesource distribution installation instructions.

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

PM2 still wants to call node, even though the newer version uses the command nodejs. I hacked it by replacing the node binary with a sim link like this:

mv /opt/bitnami/nodejs/bin/node /opt/bitnami/nodejs/bin/node.old
ln -s /usr/bin/nodejs /opt/bitnami/nodejs/bin/node

and this seems to work fine. But would prefer to simply change a config in PM2 to point to the new binary.

What is the best way to make pm2 compatible with an upgrade to nodejs 4.4.x?

Update: these are the places where node exists on this server

root@ip-172-30-1-190:/usr/bin# find / -name "node" -type f
/opt/bitnami/nodejs/bin/node
/var/lib/dpkg/alternatives/node
/usr/local/bin/node
/usr/local/n/versions/node/4.4.1/bin/node

I originally tried to upgrade node using npm and the n package using this tutorial, which accounts for the /usr/local/n/versions/node/4.4.1/bin/node line.

steampowered
  • 633
  • 2
  • 11
  • 25

2 Answers2

0

If you had node and nodejs on your system, why did you remove node?
What is /opt/bitnami/nodejs/bin/node? That is no official path to neither node nor nodejs.

When installling node.js 4.x, Ubuntu configured your system so that node is just an alternative name for the new nodejs binary to not break existing systems. So in your case, you should not have had to create the symlink.

This is how your system should be configured:

root@server:~# update-alternatives --get-selections | grep node
js                             auto     /usr/bin/nodejs
node                           auto     /usr/bin/nodejs

Since you manually deleted the node link, the output of the above command may be the same, but it is probably broken. Unless you need the Amateur Packet Radio Node program (node), I would suggest that you repair it and let Ubuntu maintain symbolic links determining default commands.

# Remove the symlink and remove the rest of a broken "update-alterantive" configuration:

unlink /opt/bitnami/nodejs/bin/node
unlink /opt/bitnami/nodejs/bin/node.old
update-alternatives --remove-all node
update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
Daniel
  • 6,940
  • 6
  • 33
  • 64
  • I put the `node` binary back the way it was using `mv node.old node` and then ran the last two lines of your final code block, the lines with `update-alternatives` (did this in a sandbox EC2 AMI for testing). However, the problem with PM2 calling `node` instead of `nodejs` persists. I also added some more additional information at the end of my OP. [This instance was originally a prepared instance from Bitnami, which I turned into an EC2 instance.](https://aws.amazon.com/marketplace/pp/B00GXYEEA4) – steampowered Apr 06 '16 at 00:08
  • It turns out someone created an entire package centered around a 2500 line bash script purposed for upgrading node and managing various node versions. It's well documented and up to date. This solved my problem: https://github.com/creationix/nvm – steampowered Apr 06 '16 at 00:28
0

Use NVM, which is a NodeJS package manager with many contributors and acceptance by the NodeJS community. https://github.com/creationix/nvm

This question is also answered on Stackoverflow: https://stackoverflow.com/a/12570971/404699

Caveat: nvm installs into a user's home directory. So if you use another tool to manage node processes, such as pm2, then you need to specify the new name of the node process (nodejs vs node) in order to experience the version nvm sets (if going from v0.12.x to v4.x for example). This is because nvm links node to nodejs only under the installed user's profile.

steampowered
  • 633
  • 2
  • 11
  • 25