Skip to content

NVM Node Version Not Switching Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about NVM Node Version Not Switching Fix. We cover key concepts, practical examples, and best practices.

The Problem

You run nvm use 18 but node --version still shows the old version. Or you open a new terminal and the Node version reverts. NVM changes are shell-specific and do not persist across sessions.

Quick Fix

Step 1: Run nvm use in the current shell

# Wrong — nvm not activated for this shell
node --version
# v16.0.0

# Right — switch version in this shell
nvm use 18
node --version
# v18.17.0

Expected output: The Node version changes for the current terminal session.

Step 2: Set a default Node version

nvm alias default 18

Expected output: New shells default to Node 18.

Step 3: Source nvm in your shell profile

# Add to ~/.zshrc or ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Expected output: NVM is available in every new terminal.

Step 4: Use .nvmrc for project-specific versions

# In project root
echo "18" > .nvmrc

# Then in the project directory:
nvm use
# Automatically reads .nvmrc and switches to Node 18

Expected output: Entering the project directory switches to the correct Node version.

Step 5: Automatically switch with shell hook

Add to ~/.zshrc:

autoload -U add-zsh-hook
load-nvmrc() {
    if [[ -f .nvmrc && -r .nvmrc ]]; then
        nvm use
    fi
}
add-zsh-hook chpwd load-nvmrc

Expected output: The Node version switches automatically when cding into a project with .nvmrc.

Step 6: Check installed versions

nvm ls

Expected output: Lists all installed Node versions with aliases.

->     v18.17.0
       v20.11.0
default -> 18 (-> v18.17.0)

Step 7: Install a missing version

nvm install 20
nvm use 20

Expected output: Node 20 is installed and activated.

Prevention

  • Set a default alias: nvm alias default 18
  • Create .nvmrc in every project
  • Add NVM sourcing to your shell profile
  • Use nvm ls to confirm versions are installed before switching

Common Mistakes with node version

  1. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  2. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  3. Misunderstanding that String is [Char] with poor performance for large text operations

These mistakes appear frequently in real-world NVM code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does nvm use work but node --version shows the old version?

NVM modifies the PATH in the current shell. If nvm use succeeds but node still points to the old version, another Node installation (Homebrew, system package) may have higher priority in PATH. Check which node and ensure NVM's PATH entry comes first.

Can I use nvm with Fish shell?

Yes. Install bass or nvm.fish for Fish compatibility. Or use fisher to install jorgebucaran/nvm.fish. The fish shell uses different syntax than bash/zsh, so the standard NVM sourcing script does not work directly.

What is the difference between nvm and fnm?

NVM is the original Node version manager, written in bash. fnm (Fast Node Manager) is a Rust-based alternative that is faster and supports automatic version switching via .node-version files. Both support .nvmrc. fnm is recommended for projects that need faster shell startup.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro