How to Run multiple Versions of NodeJS with nvm
nvm use v10.x.x
Use multiple node Versions by using nvm — node version manager: nvm use v10.x.x
WHY: Easy to switch between multiple node versions
When you are a NodeJS developer and you develop/run multiple applications on the local machine, this is a problem that you might have definitely encountered. This problem has become worse since new features are pouring into NodeJS and you have to keep up with the flow. For example, say you have currently few applications running on NodeJS version 4.x.x and you need to go for ES6 features using NodeJS 6.x .x. At this moment, you need both of these applications running on top of different Node.JS versions without using containers such as Docker in your local machine.
WHAT I want:
Upgrade my node version from v8.4.0 to node latest version (v10.15.3). But I can easily to switch back to the old version (by using this command: nvm use system)
HOW: Install multiple NodeJS Versions with NVM
Then use command nvm use v10.x.x to switch between installed node versions
1. Check current node version
node --version
2. Install nvm [if it’s not installed]
To install or update nvm, you can use the install script using cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
To verify whether nvm has been successfully installed
Run the following command which should output
nvm
if it has been correctly installed
command -v nvm
More info check here: https://github.com/creationix/nvm
3. Install any node version you want then switch between them
To install the latest node version
nvm install node # "node" is an alias for the latest version
To install the specific node version
nvm install v8.4.0 #this will install 6.14.4
nvm install v10.15.3 #this will install 10.15.3
List available node versions to install
nvm ls-remote
To check node versions are installed
nvm ls
To use a specific node version
Once the node version is installed, you can switch to it anytime by running the following command.
nvm use v10.15.3
To switch to the old node version (system)
If you want to use the system-installed version of node, you can use the special default alias “system”:
nvm use system #in my case my system node version is v8.4.0
or
nvm run system --version
To run a script app.js
on any installed NodeJS version, you can run the command:
nvm run 8.4.0 app.js
You can also run it as:
nvm exec 8.4.0 node app.js
Conclusion
My Name is LuongNhuToan. I’m a Hungry Solopreneur, Full-Stack Software Engineer passionate about turning ideas into real products. Hey YOLO! (You only live Once).
If you enjoyed this article, please clap n number of times and share it! Thanks for your time.
If you enjoyed the article consider checking out my site LuongNhuToan.com