Best way to update & manage your node.js versions

Paul Shan Tue Feb 21 2017

Many a times you face issues with the version of your installed node js. Some packages may ask for latest versions to work smoothly and some others may say they can not work properly with the latest versions. So sometimes the versions of node js really become a headache and you face the requirement to upgrade or downgrade them.

What I do not prefer

There are couple of ways to do that and I’ve found one of the most popular ways people described is by using the npm package n.
But I found it not up to the mark due to the following reasons.

  • Lot of people reported about the package not being stable.
  • Unnecessary requirement for sudo.
  • Slower than nvm.
  • The community is with nvm. Right now nvm has 3 times the stars than n in github.

What I do prefer

I think you already guessed what I want to say. Yes, I think nvm is a better and secure way to update, manage or remove your node js versions. I personally am doing upgrade and downgrade all the times now a days because I work both with ember-cli and angular-cli. Ember-cli wants the node to be below v6.9 and angular-cli wants it above 6.9. So you can guess my situation.

Manage Node js with nvm (Mac/Linux)

Step 1

First of all you need to have nvm (node version manager) installed in your computer. You can run the following curl command to install that.

curl -o- | bash

This should be sufficient to install nvm properly without errors. However if you want to check details or other ways about installation, you can check the document in github.

Step 2

Now that your nvm is installed and ready to be used; install the required version of node.js using nvm in your computer. The command below will so it for you.

nvm install 7.0.0

You can install multiple versions of node js too.

Step 3

Now that your desired version of node js is installed; you can switch to that using the command below.

nvm use 7.0.0

The command above will make the current used version of node js in your computer as 7.0.0. To verify it, you can run the version command of node.

node -v

Check the installed versions

If any any point you want to see which versions are installed, you can run the following nvm command to list all of them.

nvm ls

Delete a particular version

Even though multiple installed versions will not bother you; as at a time you will be using only one. But if you feel you have some unnecessary versions you can always remove them using the following command.

nvm uninstall 6.0.0

Update node js to latest version

Many a time you need to install the latest available node.js in your machine. However going to the official node.js website, finding out the latest version and installing and running that using the previously mentioned steps are a little tedious task. That’s why I’ve came up with the following bash function.

update_nodejs () {
    NODE_LATEST=$(nvm_remote_versions | grep '^v' | tail -1)

    echo "Updating node.js from ${NODE_CURRENT} to ${NODE_LATEST}..."

    nvm install ${NODE_LATEST}

    nvm use ${NODE_LATEST}

All you need to do is to open up your .bash_profile and insert this code snippet over there. Restart your terminal & you will be able to use the command update_nodejs, which will update the node.js in your machine to the latest version.

There is a problem with nvm when using global packages. If you install a package globally and then switch the node js version to some other; you wont be able to access the the global package there. To resolve this, check how to forward global packages in nvm.


Written By

Paul Shan


  • E


  • R

    React JS

  • C


    Cascading style sheets only

  • S


    Search engine optimization

  • E


  • C


    wordpress, drupal, jumla, magento and more

Show All


advanced js
Web development
vue css
social share buttons
react datetime picker
jquery chart library
instant search using vue
event loop
best practices

Show All