Upgrade node 0.12.x to nodejs 4.4.x using pm2

node.jspm2

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.

Best Answer

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
Related Topic