The nvm: command not found error after a terminal restart is the most common and frustrating roadblock you will hit when trying to update Node.js. Properly updating your runtime environment requires correctly configuring your shell profile and migrating your global packages so you do not break your existing projects.

  • Current LTS Recommendation: Node.js 20.x LTS or higher
  • Safest Update Method: NVM (Node Version Manager)
  • Global Package Migration: --reinstall-packages-from=default
  • Version Check Command: node -v

Should You Choose LTS or Current?

Always choose the LTS (Long Term Support) version for your production environments and daily development workflows. LTS releases guarantee critical bug fixes and security updates for three years. This stability ensures your dependencies and frameworks run without unexpected deprecation warnings.

The Current version offers early access to experimental JavaScript features. You should only install Current if you are actively testing a new library that specifically requires those cutting-edge API features. Otherwise, sticking to LTS prevents sudden pipeline failures.

Step 1: Check Your Current Node and NPM Versions

Before changing anything on your system, you need to know exactly what you are running. Open your terminal or command prompt.

Run the node version check command: node -v

Then check your package manager version: npm -v

Take note of these numbers. You will need them to verify that your update process actually worked.

Method 1: The Safest Way to Update Node.js (Using NVM)

Node Version Manager is the absolute best tool for handling Node.js updates. It allows you to install multiple versions side by side and switch between them instantly. This method eliminates the permission errors you usually get when using official installers.

Updating via nvm-windows

Windows users need a specific wrapper because the original NVM is a bash script. You can use the nvm-windows release from its official GitHub repository. Open PowerShell as an administrator to avoid elevation issues.

Run the following command to see all available releases: nvm list available

Find the latest LTS version number and install it: nvm install 20.11.0

Activate the newly installed version: nvm use 20.11.0

Updating via NVM for macOS and Linux

macOS and Linux environments handle NVM natively through your shell profile. You simply fetch the new version directly from the remote registry.

Install the latest LTS release: nvm install --lts

Set this new version as your system default so it persists across sessions: nvm alias default 'lts/*'

How to Migrate Global Packages to the New Version

Developers often hesitate to update because they fear losing their global packages like TypeScript or Nodemon. NVM has a built-in flag to seamlessly migrate these packages during the installation.

Use this command to install the new version while copying all global modules from your current active setup: nvm install 20.11.0 --reinstall-packages-from=default

This single line saves you from manually hunting down and reinstalling your essential CLI tools.

Fixing nvm: command not found After Restart

macOS uses Zsh by default, while older systems or Linux might use Bash. If you restart your terminal and lose the NVM command, your shell profile is missing the initialization script.

You need to add the NVM export script to your ~/.zshrc or ~/.bashrc file. Open your profile configuration and paste the following block at the very bottom:

export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Save the file and run source ~/.zshrc to reload your environment. The NVM command will now work perfectly every time you open a new window.

Project-Specific Versions with .nvmrc

Working on multiple legacy projects means you cannot force every repository to use the newest Node.js version. You can create a simple .nvmrc file in your project root directory.

Inside this file, just write the version number, like 18.17.0. When you navigate to this folder in your terminal, simply type nvm use and the system will automatically switch to the exact version required for that specific project.

Method 2: Updating Node.js Using the n Package (macOS/Linux)

The n package is an incredibly lightweight alternative to NVM for Unix-based systems. It is essentially an NPM package that manages Node.js versions. You cannot use this method on Windows.

First, install the package globally: npm install -g n

Then, tell it to fetch and install the latest stable version: sudo n stable

You will need administrator privileges for this step because the n package modifies system-level directories.

Method 3: Updating via Package Managers (Homebrew, Winget, Chocolatey)

System package managers offer a convenient way to keep Node.js updated alongside your other software.

On macOS, you can use Homebrew: brew upgrade node

On Windows, Winget has become the modern standard over Chocolatey: winget upgrade OpenJS.NodeJS

While these commands are fast, they lack the flexibility of NVM. They overwrite your current installation and make it very difficult to quickly downgrade if a new version breaks your local development environment.

Method 4: Using the Official Node.js Installer

Downloading the MSI or PKG file directly from the Node.js website is the most traditional update path. You just run the executable and click through the setup wizard.

This method is highly rigid. It installs Node.js globally and often leads to root permission conflicts later on when you try to install global NPM packages.

Do You Need to Uninstall the Old Version First?

If you are using NVM or the n package, you do not need to uninstall anything. These tools manage multiple versions concurrently.

However, if you are upgrading via the official Windows MSI installer from a very old major version, you should remove the old installation via the Control Panel first. This prevents registry conflicts and orphaned environment variables.

How to Update NPM Separately

Node.js comes bundled with NPM, but NPM updates much more frequently than Node.js itself. You can easily upgrade your package manager without touching your Node runtime.

Run this command to force an update to the absolute latest version: npm install -g npm@latest

Restart your terminal and run npm -v to confirm the successful upgrade.

Troubleshooting Common Node.js Update Errors

Updating complex environments sometimes leaves residual configuration issues. You can fix the most common terminal errors with a few diagnostic commands.

Diagnosing PATH Conflicts (Using which node)

Sometimes you successfully install a new version, but node -v still shows the old one. This happens when you have multiple Node.js installations fighting for priority in your system PATH.

Run this command to see exactly where your terminal is finding Node.js: which node

If the path points to Homebrew instead of NVM, you need to open your shell profile and ensure the NVM export script is placed at the very bottom, below any Homebrew configurations. The same PATH conflict pattern shows up when upgrading pip in Python alongside Node.js on the same machine.

EACCES Permission Denied Errors

You will see EACCES errors when NPM tries to write to a directory owned by the root user. This almost always happens if you installed Node.js using the official web installer instead of a version manager. If you need to set environment variables on Windows to fix a broken PATH, that article covers both the GUI and PowerShell methods.

You can fix this by changing the ownership of your hidden NPM directories to your current user profile. Never use sudo to install NPM packages, as it creates massive security vulnerabilities.

Corrupted NPM Cache (npm cache clean)

If your installations keep failing or hanging indefinitely after a major Node.js update, your local cache is likely corrupted.

Force clear the package cache with this command: npm cache clean --force

This wipes the corrupted temporary files and forces NPM to fetch clean registries on your next install attempt.