Installing NVM (Node Version Manager) on Linux is a straightforward process that can save you a lot of headaches when managing multiple Node.js versions. We’ve all been there—dealing with version conflicts and compatibility issues. Isn’t it frustrating? That’s why today, I’m excited to guide you through this hassle-free installation process.

If you’re like us, you value your time and efficiency. With NVM, you can switch between Node.js versions like a pro. We’ll walk you through each step like a helpful friend. Did your last installation go sideways? No worries! We’ll troubleshoot any common pitfalls together.
Before we start, grab your favorite snack or a cup of coffee. We promise this won’t take long. By the end of this post, you’ll have NVM up and running, ready to make your development life smoother. Let’s dive in and get coding!
Contents
Setting Up Node.js with NVM
Let’s dive straight into the nitty-gritty of installing and managing Node.js using NVM. We’ll cover how to install NVM across different operating systems and how to manage Node.js versions once NVM is in place.
Installing NVM on Different Operating Systems
First, we need to get NVM up and running on our system. The installation process varies slightly depending on the operating system you’re using.
Linux and macOS:
- Use
curlto download the installation script:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash - To apply the changes, source your profile file:
source ~/.bashrcIf you’re using
zsh, use:source ~/.zshrc
Windows:
- Download the NVM for Windows installer from the GitHub repository.
- Run the
.exefile and follow the on-screen instructions.
WSL (Windows Subsystem for Linux):
- Follow the same steps listed for Linux.
Node.js Installation and Management
Once NVM is installed, it’s time to install Node.js.
Installing a Specific Node.js Version:
- List available versions:
nvm ls-remote - Install a specific version:
nvm install 14.17.0 - Use the installed version:
nvm use 14.17.0
Managing Multiple Versions:
NVM makes it simple to switch between Node.js versions:
- Check installed versions:
nvm ls - Switch to a different version:
nvm use 10.15.3
Setting a Default Version:
- To always use a particular version by default:
nvm alias default 14.17.0
Using NVM ensures that we always have the right version for our projects without any hassle. It’s a lifesaver when juggling multiple Node.js environments.
Working with Different Node.js Versions
Using Node Version Manager (NVM), we can easily switch between multiple versions of Node.js and set a default version for our workflow. This section will guide us through selecting and switching between versions and configuring the default version globally.
Selecting and Switching between Versions
First, let’s talk about switching between Node.js versions. NVM simplifies this with a few commands:
-
List Installed Versions: To see all installed Node.js versions, we can use
nvm ls. This command will show us a list of versions available on our system. -
List Available Versions: If we want to see all available Node.js versions that we can install, we use
nvm ls-remote. This list includes all versions, including long-term support (LTS) versions. -
Install a Specific Version: If we need a specific version, we simply run
nvm install <version>. For example,nvm install 14.17.0installs Node.js version 14.17.0. -
Switch Versions: To switch to a different installed version, we use
nvm use <version>. For instance,nvm use 14.17.0changes to Node.js version 14.17.0.
Switching between many Node.js versions helps ensure compatibility with different projects, enabling us to run legacy code or test new features efficiently.
Default Version and Global Configuration
Setting a default Node.js version ensures that we consistently use the same version for all our terminal sessions. This can be particularly useful when working on multiple projects.
-
Set Default Version: We can set a default version using
nvm alias default <version>. For example,nvm alias default 14.17.0sets version 14.17.0 as the default. -
Global Version File: Some projects include a
.nvmrcfile specifying a Node.js version. By runningnvm use, NVM will automatically switch to the version specified in this file. -
Environment Variables: For a more permanent setup, we might add the
NVM_DIRenvironment variable to our shell profile (e.g.,.bashrcor.zshrc). This variable ensures NVM is sourced correctly every time we open a new terminal.
By configuring a default Node.js version and utilizing global settings, we minimize version conflicts and streamline our development process.
Advanced Usage and Troubleshooting
We’ll look into how you can customize your NVM and Node.js environments to suit your specific needs and how to solve common installation issues you might face.
Customizing NVM and Node.js Environments
NVM allows us to manage multiple Node.js versions with ease. Aliases come in handy for setting meaningful names for different Node.js versions. For instance, nvm alias default 14.17.0 sets the default Node.js version to 14.17.0.
Environment variables can be modified. By adjusting NVM_BIN and NVM_INC, you can customize where binaries and include files are located.
export NVM_BIN=/your/custom/path
export NVM_INC=/your/custom/path/include
If you want custom colors and command-line completion, add --no-use and nvm_source to your .bashrc.
export NVM_CD_FLAGS=""
export NVM_RC_VERSION="0.35.3"
Testing different environments with NVM is streamlined by using .nvmrc files in your projects. This handy file lets us specify a Node.js version for a particular project.
Solving Common NVM and Installation Issues
Occasionally, you might run into installation errors. If you receive command not found, it may indicate that the install script didn’t source properly.
First, in your terminal, run:
source ~/.bashrc
or for macOS and Linux distributions like Ubuntu, CentOS, and Debian, ensure you followed all necessary steps.
Verify NVM Installation:
command -v nvm
If permissions issues occur, make sure your user owns the installation directory and isn’t running the script with sudo.
Tracking down compatibility issues is essential. Use environment variables like NVM_SOURCE and ensure you have the correct node_version.
If npm global packages are giving trouble, check your PATH settings. Sometimes, global packages might not be found. You can export the updated path:
export PATH="$PATH:/your/custom/path"
By understanding these strategies and solutions, we can adeptly navigate the advanced uses and potential pitfalls of NVM.