How to Find the Current Node Stable Version Using NVM for Your Development Environment

Use nvm ls-remote --lts to identify the version marked with "(Latest LTS)" and install it with nvm install --lts to ensure you always have the current Node stable version using NVM aligned with the official Node.js release channel.

Node.js defines its Long-Term Support (LTS) lifecycle through specific macros in its source code, and NVM (Node Version Manager) mirrors these release channels directly from the Node.js distribution server. Understanding how the nodejs/node repository marks stable releases helps you configure a reliable development environment that automatically tracks the latest LTS line without manual version hunting.

How Node.js Marks LTS Releases in the Source Code

The Node.js repository encodes release channel information directly in its C++ headers, which the build system consumes to determine if a given commit represents a stable release.

The Version Header File

In src/node_version.h, the repository maintains macros that describe the build’s release status:

#define NODE_VERSION_IS_LTS 0
#define NODE_VERSION_LTS_CODENAME ""
#define NODE_VERSION_IS_RELEASE 0

When the release team cuts a new LTS, they update these values. The NODE_VERSION_IS_RELEASE macro specifically indicates whether the current HEAD represents a published stable version rather than a development nightly.

Build System Integration

The Makefile at line 944 extracts the NODE_VERSION_IS_RELEASE flag to decide build behaviors:

sed -ne 's/#define NODE_VERSION_IS_RELEASE \([01]\)/\1/p' src/node_version.h

This extraction ensures that only properly tagged releases trigger stable build paths. Additionally, CI workflows like .github/workflows/linters.yml set the environment variable NODE_VERSION to lts/*, guaranteeing that automation tooling recognizes the latest LTS designation.

Querying the Current Node Stable Version Using NVM

NVM does not parse the Node.js source code directly. Instead, it queries the official download index at https://nodejs.org/dist/, which is generated from the same Git tags that populate the NODE_VERSION macros in the repository.

Listing Remote LTS Versions

Run the following command to see all LTS releases with the current stable version highlighted:

nvm ls-remote --lts

The output annotates the newest LTS with "(Latest LTS: Codename)", making it immediately identifiable:


v20.12.2   (Latest LTS: Iron)
v18.20.4   (Latest LTS: Hydrogen)
v16.20.2   (Latest LTS: Gallium)

This annotation appears because NVM parses the Node.js distribution index, which reflects the same release metadata defined in src/node_version.h when the release was tagged.

Installing and Setting Defaults

To install the specific version shown as "Latest LTS":

nvm install 20.12.2
nvm alias default 20.12.2

Alternatively, use the generic LTS flag to always install whatever NVM determines is current:

nvm install --lts
nvm alias default $(nvm version)

The --lts flag resolves against the remote index in real-time, ensuring you receive the same version that the Node.js build system would designate as NODE_VERSION_IS_RELEASE=1 in the source tree.

Automating LTS Installation in Development Workflows

For teams maintaining consistent environments across machines, scripts can automate the detection and installation of the current stable version.

Bash Script Example

This script parses NVM’s remote list to find the exact string marked as "Latest LTS" and sets it as default:

#!/usr/bin/env bash
export NVM_DIR="${HOME}/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

latest_lts=$(nvm ls-remote --lts | grep -i '(latest lts' | awk '{print $1}')

if [[ -z "$latest_lts" ]]; then
  echo "Falling back to generic --lts"
  nvm install --lts
  latest_lts=$(nvm version)
else
  echo "Installing latest LTS: $latest_lts"
  nvm install "$latest_lts"
fi

nvm alias default "$latest_lts"

Node.js Script Example

For Node-based automation tools, you can invoke NVM through child processes:

const { execSync } = require('child_process');

const latest = execSync('nvm ls-remote --lts | grep -i "(latest lts" | cut -d" " -f1')
  .toString().trim();

const installed = execSync(`nvm ls ${latest}`).toString();
if (!installed.includes(latest)) {
  execSync(`nvm install ${latest}`, { stdio: 'inherit' });
}

execSync(`nvm alias default ${latest}`, { stdio: 'inherit' });
console.log(`Node ${latest} is now the default stable version`);

Summary

  • Source alignment: The src/node_version.h file and Makefile (line 944) in the nodejs/node repository define what constitutes a stable release through the NODE_VERSION_IS_RELEASE macro.
  • Remote verification: NVM queries nodejs.org/dist/, which reflects the same Git tags that trigger the release macros in the source code.
  • Reliable commands: Use nvm ls-remote --lts to view the current stable version and nvm install --lts to install it.
  • Environment consistency: Setting NODE_VERSION=lts/* in CI configurations (as seen in .github/workflows/linters.yml) ensures parity between local development and automated builds.

Frequently Asked Questions

How does NVM know which version is the current LTS?

NVM downloads the version index from https://nodejs.org/dist/, the official Node.js distribution server. This index is generated from the repository’s release tags, which correspond to the NODE_VERSION_IS_LTS and NODE_VERSION_IS_RELEASE macros set in src/node_version.h during the release build process. When a version is tagged as the latest LTS, NVM annotates it with "(Latest LTS)" in the ls-remote --lts output.

What is the difference between nvm install lts/* and nvm install --lts?

Both commands resolve to the same version, but nvm install --lts is the explicit flag syntax that tells NVM to query for the Long-Term Support channel specifically. The lts/* argument is the version alias format used by NVM internally and matches the NODE_VERSION environment variable pattern used in CI workflows like .github/workflows/linters.yml.

Can I trust NVM's LTS designation to match the official Node.js documentation?

Yes. Because NVM pulls directly from nodejs.org/dist/, which is the canonical source populated by the Node.js release team when they update src/node_version.h and tag releases, the "Latest LTS" marker in NVM is synchronized with the official stable channel. This makes nvm install --lts the most reliable method for obtaining the current node stable version without manually checking changelogs.

Why does src/node_version.h show NODE_VERSION_IS_LTS 0 on the main branch?

The main branch in the nodejs/node repository represents active development. The NODE_VERSION_IS_LTS macro is set to 1 only on release branches (e.g., v20.x, v18.x) when the release team designates that line as entering LTS status. The Makefile checks NODE_VERSION_IS_RELEASE to determine if the current checkout should be treated as a stable build, which is why you should use NVM’s remote lookup rather than building from source to get the current stable version.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →