Installing Node.js Tutorial: using nvm
This blog post was originally published in NodeSource webpage by Tierney Cyren and updated by Liz Parody and Mike Nedelko on March 2020.
As with any programming language, platform, or tool, the first step to using it is getting it installed. Many of them typically come with a speedy way to upgrade when a new version is available.
By default, there isn't a way to upgrade the version of Node.js from within Node.js itself. That said, there is a fantastic tool for the community called nvm Node Version Manager that allows you to manage the versions of Node.js that you have installed locally.
One awesome aspect of nvm
is that it manages the versions of Node.js you have installed, it doesn't just upgrade them. This means you can have the latest version of Node.js, the latest versions of all the LTS release lines, and any number of other versions you want to use or test installed and ready to be used simultaneously.
In this quick tutorial, we will take a look at how to install nvm, and then how to start using it as your version manager for Node.js. Once we have completed the tutorial, you will be ready to take the next step with Node.js.
This guide covers installing nvm on macOS and Linux - note that all versions of Node.js may not support every version of macOS or Linux.
Here is the abbreviated guide, highlighting the major steps:
- Download the nvm install script via cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
- Ensure that nvm was installed correctly with
nvm --version
, which should return the version of nvm that is installed. - Install the version of Node.js you want
- Install the latest version with
nvm install node
- Use the latest version with
nvm use node
- Install the latest LTS version with
nvm install --lts
- Use the latest LTS version with
nvm use --lts
- Install the latest version with
In some cases, like when installing Node.js releases from their source or installing versions of Node.js before 0.8.6
(when the project started shipping binaries), you will need to ensure that your system has the appropriate C++ build tools.
For LTS and modern releases, you will not need this step. That said, it's a nice to have to ensure that the majority of requirements are met in any scenario.
On macOS, you have two options for a C++ compiler: the full XCode application or the stand-alone Command Line Tools portion of Xcode.
To get these on macOS, you can follow these steps:
- Open your terminal of choice
- Run
xcode-select --install
as a command- A popup will appear
- Select
Install
- Allow the download to run to completion
- If the installation went uninterrupted, you should have the necessary tools to use nvm!
On Linux, the C++ compiler will vary from distribution to distribution. For example, on Debian and Ubuntu, you will need to install build-tools
and libssl-dev
, but this may be different on your given Linux distribution.
To get build-tools
and libssl-dev
on Debian and Ubuntu distributions, you can run these commands:
https://gist.github.com/d58bde20126cba8be60c646423e94e35
Once you have the right C++ compiler for your system, it is now time to run the nvm install script. These are the single-step install scripts for both macOS and Linux. You have the option of cURL or Wget but both achieve the same result.
Note: If your Linux system doesn't have either cURL or Wget, you can run sudo apt-get install curl
and use the cURL method.
To install nvm with the cURL method, run the following command in your terminal:
https://gist.github.com/02a214d288145b00e065c23a4f743a3c
To install nvm with the Wget method, run the following command in your terminal:
https://gist.github.com/d065f46bf58f37c6cd6c5c4967f8ea22
You can install nvm with Homebrew with the script:
https://gist.github.com/91ecc090faefbf6cafaa7d158607949b
If you already have Node.js installed, uninstall it and then you can install nvm.
https://gist.github.com/809e9f04f693beaf8a06d3a919e90738
For more details visit: Install NVM On Mac With Brew
After running the install script from Step 2, nvm should be successfully installed. To ensure that nvm is up and running on your machine, you can test it with the following command:
https://gist.github.com/c780c4a0cbf71c1442f40663f821ca7d
This command will return something like (though not necessarily exactly) the following:
https://gist.github.com/ebf876a85a146b045111f7754e1eb185
If you are using macOS, you may be missing a .bash_profile
file to troubleshoot this, you can run touch ~/.bash_profile
in your command line and re-run the install script.
If the problem persists after that, you can open the existing .bash_profile
file (using your favorite text editor) and add the following line to it:
https://gist.github.com/e66696d9624f01e742fc0ef692b9fa0d
If you are still having issues, you can take a peek at this issue to find a discussion of the problem and a collection of possible resolutions.
Congratulations! You can now use nvm
- a tool to easily allow you to manage and swap out the versions of Node.js you have installed locally. Now, let's get you started with doing just that.
To install the latest available version of Node.js, you can use the following command:
https://gist.github.com/fe8482f465673ecc3e0f68f59cdeaa10
Next, to use that version of Node.js in any new shell, you can simply run the use
command:
https://gist.github.com/d10519d19634a4c04dacaba3c43a2f3b
To install the latest available LTS version of Node.js, you can run the following command:
https://gist.github.com/99a98306009f9c9f91092dd83c9ca8d3
And to use that latest LTS version of Node.js in any new shell, you can simply run the use
command:
https://gist.github.com/3e4d630c00a9112918c42b482d35bfca
The first step is to install NSolid. You should install the runtime as described in the documentation here:
After this process NSolid will be your default Node version. To install NSolid, It’s important to take into account that there should not be any other Node.js version installed already.
Then, install nvm as mentioned in Step 2 and you can use the same nvm commands as regular. nvm doesn’t update NSolid versions, to update NSolid, follow the instructions here.
You should be able to see all versions already installed and NSolid will show up as system, to use it just execute:
https://gist.github.com/fab93265cd2c17306e34e323a8369279
Now that you have a fantastic version manager for Node.js. It's time to start building!
We have some resources to get you kickstarted! Both the breadth and depth of the Node.js and the JavaScript ecosystems are quite large - in addition to the developer tools like NodeSource NSolid, NodeSource as a number of tutorials, guides, and articles to help you get kick started with Node.js.
That said, if you want to keep in touch with the Node.js ecosystem, you should follow @NodeSource on Twitter! We will keep you updated with important news from the core Node.js project, and more.