How to run multiple node versions side by side

Last updated 5 weeks ago

This is going to be a quick tutorial on how to run multiple node versions side by side. There are many different ways to do it but this works well for me.

First I compile node versions from source and I set them up in the following directory structure:

/home/pkrumins/installs/node-v0.8.20
/home/pkrumins/installs/node-v0.8.21
/home/pkrumins/installs/node-v0.10.3
/home/pkrumins/installs/node-v0.10.22

When compiling node I simply specify --prefix=/home/pkrumins/installs/node-vVERSION, and make install installs it into that path.

Next I've this bash alias:

function chnode {
 local node_path="/home/pkrumins/installs/node-v1ドル/bin"
 test -z "1ドル" && echo "usage: chnode <node version>" && return
 test ! -d "$node_path" && echo "node version 1ドル doesn't exist" && return
 PATH=$node_path:$PATH
}

Now when I want to run node 0.8.21, I run chnode 0.8.21 to update the path:

$ chnode 0.8.21
$ which node
/home/pkrumins/installs/node-v0.8.21/bin/node
$ node --version
v0.8.21

Or if I want to run node 0.6.18, I run chnode 0.6.18:

$ chnode 0.6.18
$ which node
/home/pkrumins/installs/node-v0.6.18/bin/node
$ node --version
v0.6.18

Works for me both locally and in production. Until next time.

Read more articles →
Thanks for reading my post. If you enjoyed it and would like to receive my posts automatically, you can subscribe to new posts via rss feed or email.
What is an OSINT Browser? (And How To Get One)
How we added invoices to Browserling

AltStyle によって変換されたページ (->オリジナル) /