DEV Community

Cover image for Using multiple versions of nodejs.
mohammed afif ahmed
mohammed afif ahmed

Posted on

Using multiple versions of nodejs.

Introduction

Usually we work on different version for our nodejs project and its hard to manage them,but fortunately there is tool called NVM(node verion manager) which help to manage your node version and switch between them according to your projects.

Windows installation

Unfortunately nvm project is only for linux/macos, but...but there is another very similar project by Corey bulter,known as nvm-windows. Click this link download the nvm-setup.zip file and install it in a mundane fashion as on windows.
After installation you can use the same commands as on linux/macos.

Linux installation

In your terminal use curl to install

$ curl -o- https://raw.githubusercontent.com/nvm-sh/v0.34.0/install.sh | 
Enter fullscreen mode Exit fullscreen mode

after installation you need to add a bit of configuration in your .bashrc file or .zshrc etc. So, open the file and append the below code.

$ export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
[ -s :$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Enter fullscreen mode Exit fullscreen mode

This sets the path to directory of installation.
Reload your blog terminal, for the changes to take effect and we are good to go.

usage

So let's jump into the terminal and look at some of the commands.

  • To Install latest version of node
$ nvm install node
Enter fullscreen mode Exit fullscreen mode
  • Install specific version
$ nvm install {node_verion}

#example
$ nvm install 10.0.0
Enter fullscreen mode Exit fullscreen mode
  • command to list out all the versions installed
$ nvm ls
Enter fullscreen mode Exit fullscreen mode
  • Switching between different node versions
# to use latest version
$ nvm use node  

# for a specific verion
$ nvm use 10.0.0  
Enter fullscreen mode Exit fullscreen mode
  • Deleting node versions
$ nvm uninstall {node_version}
Enter fullscreen mode Exit fullscreen mode

Conclusion

As this was an introductory post, we looked at some of the most used commands, this is a very useful tool if you are working on multiple projects which requires different version of node. You can have a look at the official nvm https://github.com/nvm-sh/nvm gitrepo to understand thoroughly.

Liked the content?
ko-fi

Top comments (0)