GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • DevCircleRESOURCES
  • The library
  • Your learning map
  • Courses
  • Web development
  • About the library
  • Contact & corrections
  • Privacy
  • Legal notice
  • RSS feed

This view

  • Original page
  • New address

GeezerVison is showing developercircleresources.com — Node version manager: install nvm and pin a project runtime

Project note 29

Node version manager: install nvm and pin a project runtime

Install nvm on macOS, Linux, or WSL, select Node.js 24 for a project, and diagnose a terminal that keeps running the wrong version.

Updated November 17, 2026nvm 0.41.0; Bash or Zsh on macOS, Linux, or WSL

Before you start

No earlier guide required.

Save your progress
Two terminal sessions select separate Node versions; the project pins an exact runtime in .nvmrc.
The working model for this project. Follow the guide below for the complete example.

A Node version manager lets you install several Node.js releases side by side and choose which one a given terminal runs, which is handy when one project needs Node 24 and another a different major version. When an installation error appears, confirm which node your terminal actually found before you edit application code.

On macOS, Linux, and Windows Subsystem for Linux (WSL), this exercise uses nvm-sh/nvm through Bash or Zsh. Install the version manager, choose the Node 24 release used in this library’s server exercises, then write the full resolved version to a project file. PowerShell on native Windows uses another tool, so check your platform below before running these commands.

Choose the manager for your terminal

Scroll sideways if the columns extend beyond the frame.

Terminal environment Appropriate starting point What to check
Bash or Zsh on macOS or Linux nvm-sh/nvm The manager is loaded as a shell function.
Bash inside WSL nvm-sh/nvm inside that Linux distribution Install and run the Linux runtime inside WSL.
Native Windows PowerShell or Command Prompt NVM for Windows Follow that project’s current installer and command reference.

Although they share a name, the two projects are implemented differently and install differently. The commands below target nvm-sh/nvm. Installing on Windows gives your WSL shell no Linux node, and installing inside WSL leaves PowerShell unconfigured.

Install nvm and load it into the current shell

You’ll need curl, a working HTTPS connection, and Bash or Zsh. Fetch the installer from the tagged release linked in the official installation instructions:

curl -fL -o nvm-install.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh
less nvm-install.sh
bash nvm-install.sh

Once you have reviewed the script, press q to leave less. The installer normally puts nvm in your home directory and adds initialization lines to a shell startup file, and its output names the file it changed. You can open a new terminal, or load the default installation into the current one:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
command -v nvm
nvm --version

With the default setup, command -v nvm should return nvm, and the tagged release above reports 0.41.0. If you chose another installation directory, use it instead. Avoid which nvm as a check: nvm is a shell function, not a standalone executable on PATH.

Loading nvm this way lasts only for the current shell session. Future sessions need initialization in the startup file your shell actually reads. When nvm works now but disappears after you reopen the terminal, inspect that file before reinstalling anything.

Select Node 24 and verify the executable

According to the Node release table, Node 24 and Node 26 are both LTS on November 17, 2026. These exercises require Node 24, so select that major version directly. As release schedules change, nvm install --lts may choose a different major.

nvm install 24
nvm use 24
node --version
npm --version
node -p 'process.execPath'

nvm install 24 resolves to an available release in that major line rather than pinning an exact patch. node --version should begin with v24.. On the Linux check for this exercise it resolved to v24.22.3 with npm 11.19.1; as the release line is updated, your patch and npm versions may differ.

Confirm that the executable path points inside nvm’s versions/node/ directory for your selected release. Node includes npm, so these examples don’t require a separate package manager. Global npm packages are tied to their Node installation; switching versions can make a globally installed command disappear.

For a file-only exercise, parse, validate, and save JSON using this runtime. After that, launch the small HTTP server in this same terminal. Should your editor’s integrated terminal or a background task behave differently, inspect the executable in that environment too, because its setup may not match yours.

Pin the resolved version in a project

Create a new practice directory, then save the selected full version to .nvmrc:

mkdir node-runtime-lab
cd node-runtime-lab
node --version > .nvmrc
cat .nvmrc
nvm install
nvm use
node --version

The file holds a single version followed by a newline, for example v24.22.3. Running nvm install or nvm use without an argument reads .nvmrc; both commands also search parent directories. Commit the file with the project so collaborators can select the same runtime.

Writing 24 instead would let the resolved patch drift, and lts/* would let the LTS major move too. An exact pin eases reproduction but needs upkeep: install a supported patched release on purpose, run your checks, then update the file. Pinning alone brings no security updates.

Changing directories with cd won’t run nvm use automatically unless you’ve configured a shell hook to do so. Run it when entering the project. The npm lockfile captures dependency resolutions, while .nvmrc specifies the runtime; keep both if the project has dependencies.

Prove that the selection belongs to a shell

In terminal A, enter the practice directory and run nvm use, then node --version. In terminal B, load nvm and run nvm install 22 followed by nvm use 22. Repeat node --version in both terminals: A stays on Node 24, B reports Node 22.

Return to B, change into node-runtime-lab, and run nvm use. It should select the exact version recorded in .nvmrc. This simple test shows how each shell keeps its own selection rather than replacing a machine-wide installation.

Future shells that initialize nvm take their default selection from nvm alias default 24, which does not rewrite project files or switch terminals already open. Before running JavaScript tests, run nvm use to choose the project’s runtime explicitly.

Diagnose the wrong version before reinstalling

Scroll sideways if the columns extend beyond the frame.

Symptom Check Next action
nvm: command not found command -v nvm and the startup file named by the installer Load nvm.sh in the current shell; repair initialization for future shells.
nvm use reports a version is not installed Read .nvmrc and run nvm ls Run nvm install inside the project, then repeat nvm use.
node --version disagrees with the project Run command -v node, type -a node, and node -p 'process.execPath' Look for a shell alias or another installation earlier in PATH.
The editor uses another Node Run the same checks inside its integrated terminal Restart or configure that terminal, then select the project version there.
A command installed with npm -g disappeared Compare nvm current before and after switching Install only the tools needed for this runtime, or use project-local dependencies.

Don’t try sudo npm install -g to fix nvm initialization. That changes where packages are installed without explaining why the shell chose the wrong executable. First verify the node path, version, and project pin; then troubleshoot any remaining dependency error.

The base image, not your host shell, decides the runtime inside a container. The Docker Node exercise demonstrates that boundary in a complete downloadable project.

Sources: nvm 0.41.0 README, Node.js releases, and NVM for Windows.

Keep building

  • JSON (JavaScript Object Notation): parse and validate a file

    Read a local JSON file with Node.js, distinguish syntax errors from invalid fields, and save a checked copy without overwriting the original.

  • Dockerize a Node.js application and check the running container

    Package a tiny server, run it as an unprivileged user, and check the deployed process before opening traffic.

  • REST API tutorial: validation before persistence

    Design a small notes endpoint with a bounded request body, explicit errors, and predictable status codes.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.