Trying new versions of Node.js with NVM

Shane Osbourne
InstructorShane Osbourne
Share this video with your friends

Social Share Links

Send Tweet
Published 9 years ago
Updated 5 years ago

It's possible to install and run multiple versions of Node.js using a project called NVM. In this lesson we'll walk though the installation, how to try out Node.js version 4.0.0 & even how to configure Webstorm to use any nvm-installed version. Note: NVM works on Mac OSX and Linux only. For a Windows version (with the same commands) see https://github.com/coreybutler/nvm-windows or https://github.com/hakobera/nvmw

[00:05] Node.js version 4. Thanks to an updated version of v8 has some amazing language features that I really want to start using. Things such as block scoping with lat clusters, promises, and most importantly for me rF functions are all great features and I really want to start playing them.

[00:24] On to-do list in a way that doesn't affect my existing projects, however. What I mean by this is, if I type in node-v here, you'll see my default interpreter is version 012.

[00:38] If I were to go ahead and download from the home page the latest version of node, it would override this default version and when I did node-v I would see version 4 here. I don't want to be running and testing any existing projects against node 4, most of my users aren't on it yet.

[00:56] I just want to be able to play with it and see what it's like. This is exactly what the nvm project is all about. As you can see here, the node version manager is a simple batch script to manage multiple active node.js versions.

[01:12] So what it will do is download versions of nodes so that you can temporarily swap out the interpreter. We copy these lines, and then reload my config, now I can type nvm and I have the nvm program.

[01:36] We'll look at a couple of simple commands, the ones you're most likely use anyway. The first one is ls-remote. This will list all available node packages. If we type in nvm ls-remote, it's literally going to list everything. If we scroll up we can see that version 4 is right there. You can install that simply by typing nvm i4.

[02:10] Once completed, if we type node-v you can see we're now using 4.0We can do a quick test to make sure that is working, by interpreting a bit of inline code. If we say var fn = an n-line arrow function that returns 1, we see no error in the console.

[02:32] In fact, if we call it and wrap it in console.log you can see we get 1. What's really cool about this, is when we open up another terminal window and type node-v you can see that we're still back to our default interpreter. So that's really cool.

[02:54] We don't have to change the main installation on our machine, we can just use nvm to play around with any version we like. One more note on this, if you're using something like WebStorm, that can interpret your scripts for you, if we tried to run this, you're going to see again, we've got a syntax error here. This is because WebStorm doesn't know about nvm or which interpreter you'd like to use.

[03:20] One trick I like to do is go back to the command line, and once we know we're using the version of node we want, just type which node, copy this right to WebStorm, edit the configuration, and simply supply it as the node interpreter. Hit apply, close, and now when you try and run this file again, you can see it's using the interpreter that nvm installed, and it run the index.js file. If we wrap that again, we can see it works.

[04:00] One final thing, if you're sick of doing this and you want to just get rid of nvm all together, you can run nvm unload. Now to remove the installed versions of node, you would simply rm rf.nvm and now it's completely removed from your machine. Type node-v again and you can see we're back to our default interpreter.

egghead
egghead
~ 11 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today