Manage Multiple Node Versions

Venkat.R
2 min readSep 29, 2016

Node.js is a wonderful runtime environment of the decade. When come to managing different versions of Node in same machine for different application will make your life horrible.

Don’t worry, That’s not the end of the story. This article helps on how to overcome and solve this problem with right tools. In short `nvm` and `apn` or `n` and `apn` node module is my proposal to solve this issue.

Installing Node Version Manager

Node Version Manager alias NVM is Node Module which helps to maintain multiple node versions in a same machine to manage various versions.

$ npm install -g nvmor$ npm install -g n

`nvm` and `n` Node Module does not support windows. use below module.

$ npm install -g nvm-windows

Setting Run Time Configuration

The Run Time Configuration alias .nvmrc file which helps to read the version by `avn` Module and you will see below, what is `avn` module about.

$ vi .nvmrc
v4.4.7

Installing Automatic Node Version Switching

Automatic Node Version alias AVN is Node Module which helps to switch different version.

AVN provide `avn-nvm` and `avn-n` Module for NVM and N Module compatible from reading your NVM Runtime configuration file (.nvmrc).

$ npm install -g avn avn-nvm avn-n

AVN Updates Bash Profile

AVN Module updates below code in `~/.bash_profile` after its got installed, open this file and make sure its updated and copy this line `~/.profile`.

$ vi ~/.profile[[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" # load avn

Setting Automatic Node Version

After move to your project directory and create `.nvmrc` file with node version. Set up AVN by using below command. This will update the `~/.avn` File.

$ cd <project_directory>
$ avn setup

Evaluate Bash Profile

Execute the `~/.profile` only once or do it if there any change. File to make AVN commands to be available globally to invoke the command during `cd <directory>`

$ source ~/.profile

You are done!

Yes, you are completed the steps to switch automatically from one version to another and manage different version node projects in same machine.

--

--

Venkat.R

👨‍💻 React, Full Stack Engineer | Father | Career Coach | Mentor | 📗 Blogger | Ex-Yahoo, Visa, Target, Proximus— webslate.io