How to Change Node.js Version with nvm: Install and Switch Guide
To change your Node.js version with nvm, run nvm install <version> to download and compile the source from the nodejs/node repository, then nvm use <version> to activate that binary in your current shell.
The Node.js runtime does not ship with a built-in version manager, but you can change Node.js versions seamlessly using nvm (Node Version Manager). This tool manages multiple Node installations by downloading official release artifacts derived from the nodejs/node repository and compiling them according to the build instructions in BUILDING.md. When you need to switch between projects requiring different Node versions, nvm adjusts your shell’s PATH to prioritize the selected binary.
How nvm Works with the Node.js Source Repository
nvm manages versions by downloading official release tarballs from nodejs.org/dist and building them using the infrastructure defined in the nodejs/node repository. When you execute nvm install <version>, the tool performs the following steps using the source tree:
- Downloads the tarball for the requested semantic version (e.g.,
node-v18.20.0.tar.gz) from the official distribution site. - Extracts the source and runs the build steps defined in
BUILDING.mdat the repository root. - Executes the configure script (
./configure) andMakefileto compile the C++ core, includingsrc/node.cc(the runtime entry point) andsrc/uv.cc(libuv event-loop integration). - Installs JavaScript standard-library modules from
lib/fs.js,lib/http.js, and other files inlib/into the final distribution.
The resulting binary is placed in ~/.nvm/versions/node/v<version>/bin/, and nvm manipulates your shell environment to prioritize this path.
How to Change Node.js Version with nvm
Install nvm
If you have not installed nvm yet, run the official install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
After installation, reload your shell configuration to enable the nvm command:
source ~/.bashrc
# Or for zsh:
source ~/.zshrc
List Available Node.js Versions
To see every version available from the nodejs/node release distribution:
nvm ls-remote
This lists all semantic versions that can be fetched and built, including LTS (Long Term Support) releases.
Install a Specific Node.js Version
To download and compile a specific version from the repository source:
# Install the latest LTS version
nvm install --lts
# Or install an exact version (e.g., v18.20.0)
nvm install 18.20.0
During this process, nvm downloads the source tarball and executes the build pipeline defined in configure and Makefile, compiling the C++ components in src/ and installing the JavaScript modules from lib/ into ~/.nvm/versions/node/v18.20.0/.
Switch Versions in Your Current Shell
To change Node.js versions in your active terminal session:
nvm use 18.20.0
node -v
# Output: v18.20.0
The nvm use command prepends ~/.nvm/versions/node/v18.20.0/bin to your PATH, ensuring that the node and npm binaries from this version are found before any system-wide installation.
Set a Default Node.js Version
To automatically use a specific version in all new shell sessions:
nvm alias default 18.20.0
Now, any new terminal window will default to Node.js v18.20.0 without requiring manual switching.
Verifying Installation from Source
You can confirm that your active Node binary was built from the nodejs/node repository:
which node
# Output: /home/username/.nvm/versions/node/v18.20.0/bin/node
To view the exact commit hash from the repository used to build your current version:
nvm version-commit 18.20.0
# Output: v18.20.0 (node-v18.20.0) – commit: d6b0e1b...
This commit corresponds to the exact state of the source files (including src/node.cc, src/uv.cc, and lib/fs.js) used to generate that release.
Summary
- nvm downloads official tarballs generated from the
nodejs/noderepository and compiles them usingBUILDING.md,configure, andMakefileinstructions. - Run
nvm install <version>to compile and store a Node.js version in~/.nvm/versions/node/. - Run
nvm use <version>to change Node.js versions by modifying your shell’sPATH. - Run
nvm alias default <version>to persist a version across new terminal sessions. - The repository source files—including
src/node.cc,src/uv.cc,lib/fs.js, andlib/http.js—define the runtime behavior of each installed version.
Frequently Asked Questions
How do I change Node.js version with nvm?
Run nvm use <version> (for example, nvm use 18.20.0) in your terminal. This command modifies your shell’s PATH to prioritize the binary located at ~/.nvm/versions/node/v18.20.0/bin/node, effectively changing the active Node.js version for that session.
What does nvm install node version do?
When you run nvm install <version>, the tool downloads the official source tarball from nodejs.org/dist, extracts it, and executes the build process defined in the nodejs/node repository’s BUILDING.md. It compiles the C++ source in src/ and JavaScript modules in lib/ using the configure script and Makefile, then installs the resulting binary into your ~/.nvm/versions/node/ directory.
Where does nvm store installed Node.js binaries?
nvm stores all versions in ~/.nvm/versions/node/, with each version isolated in its own subdirectory (e.g., ~/.nvm/versions/node/v18.20.0/). Inside each directory, you will find the bin/, lib/, and include/ folders containing the compiled artifacts from the repository source.
How does nvm build Node.js from the repository?
nvm follows the public build instructions found in BUILDING.md at the root of the nodejs/node repository. It runs ./configure to prepare the build environment, then uses make to compile the C++ core files like src/node.cc and src/uv.cc, alongside the JavaScript standard library in lib/, producing the final executable binary.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →