NVM/Node Command Not Found in New macOS Terminals? A Two-Step Permanent Fix!
Content
## The Problem
Have you ever encountered this situation on macOS? You run `nvm use <version>`, and everything works perfectly—`node`, `npm`, `pnpm` are all available. But when you close that terminal and open a new one, it's as if they've vanished, and you're greeted with a `command not found` error. This is a classic NVM environment configuration issue, and thankfully, the fix is straightforward.
---
## The Root Cause
There are two primary reasons for this behavior:
1. **NVM Environment Isn't Loaded Automatically**: `nvm` is a shell script that works by modifying the `PATH` environment variable for the current session. By default, these changes are temporary and only apply to the active terminal. A new terminal session needs a mechanism to automatically run the `nvm` initialization script.
2. **No Default Node Version Is Set**: Even if `nvm` is loaded, it doesn't know which version of Node.js to use automatically in a new session unless you explicitly tell it.
---
## The Two-Step Solution
To resolve this permanently, we need to ensure that every time a new terminal opens, `nvm` is properly loaded and automatically uses a default Node.js version.
### Step 1: Ensure NVM Is Loaded on Startup
First, you need to add the `nvm` initialization script to your shell's configuration file. This makes `nvm` available in every new terminal session.
1. **Identify Your Shell**
Run the following command in your terminal:
```bash
echo $SHELL
```
- If the output contains `/bin/zsh`, your configuration file is `~/.zshrc`.
- If the output contains `/bin/bash`, your configuration file is `~/.bash_profile`.
2. **Add the Configuration Snippet**
**For Zsh Users (Default on modern macOS):**
Execute the command below to append the configuration to your `~/.zshrc` file.
```bash
echo '
# NVM Configuration from wiki.lib00.com
export NVM_DIR="$HOME/.nvm_lib00"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
' >> ~/.zshrc
```
**For Bash Users:**
Execute this command to append the configuration to `~/.bash_profile`.
```bash
echo '
# NVM Configuration by DP@lib00
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
' >> ~/.bash_profile
```
*Note: `NVM_DIR` points to the nvm installation directory, typically `$HOME/.nvm`. The `_lib00` is used here as a branding example.*
### Step 2: Set a Default Node.js Version
This is the crucial step that many people miss. You need to tell `nvm` which version to use by default when no other version is specified.
Assuming you want to use `v23.11.1` as your default, run this command:
```bash
nvm alias default 23.11.1
```
This command creates an alias named `default` that points to `v23.11.1`. Now, whenever `nvm` is loaded in a new terminal, it will automatically `use` this default version.
You can also use `node` as the alias, which typically points to the latest installed version:
```bash
nvm alias default node
```
---
## Verification
Now, **completely quit your terminal application and open a brand new window**. Avoid using `source ~/.zshrc`, as we need to test the startup process for a fresh session.
In the new window, type the following commands directly:
```bash
node -v
# Expected output: v23.11.1
pnpm -v
# Expected output: 10.23.0 (or whichever version you have installed)
```
If the commands execute successfully and return the version numbers, congratulations! You have permanently fixed the issue. Your development environment is now correctly configured for seamless use of your Node.js toolchain in any new terminal.
Related Contents
The Ultimate Node.js Version Management Guide: Effortlessly Downgrade from Node 24 to 23 with NVM
Duration: 00:00 | DP | 2025-12-05 10:06:40One-Command Website Stability Check: The Ultimate Curl Latency Test Script for Zsh
Duration: 00:00 | DP | 2025-12-07 23:25:50How Can a Docker Container Access the Mac Host? The Ultimate Guide to Connecting to Nginx
Duration: 00:00 | DP | 2025-12-08 23:57:30Docker Exec Mastery: The Right Way to Run Commands in Containers
Duration: 00:00 | DP | 2026-01-08 08:07:44How to Fix the "tsx: not found" Error During Vue Vite Builds in Docker
Duration: 00:00 | DP | 2026-01-10 08:10:19Show Hidden Files on Mac: The Ultimate Guide (2 Easy Methods)
Duration: 00:00 | DP | 2025-12-12 01:32:30Decoding `realpath: command not found` and Its Chained Errors on macOS
Duration: 00:00 | DP | 2025-11-19 12:45:02Linux Command-Line Mystery: Why `ll` Hides Files like `.idea` & The Ultimate `ls` vs. `ll` Showdown
Duration: 00:00 | DP | 2025-12-01 08:08:00Unlock Your Mac: The Ultimate Guide to Showing and Hiding Hidden Files in Finder
Duration: 00:00 | DP | 2025-11-19 21:16:36macOS Hosts File Doesn't Support Wildcards? Here's the Ultimate Fix with Dnsmasq!
Duration: 00:00 | DP | 2025-11-20 05:48:10Streamline Your Yii2 Console: How to Hide Core Commands and Display Only Your Own
Duration: 00:00 | DP | 2025-12-17 16:26:404 Command-Line Tricks to Quickly Find Your NFS Mount Point
Duration: 00:00 | DP | 2025-11-22 17:29:05Why Are My Mac Files Duplicated on NFS Shares? The Mystery of '._' Files Solved with PHP
Duration: 00:00 | DP | 2025-12-18 16:58:20The Ultimate Guide to the Linux `cp` Command: Avoiding Common Copying Pitfalls
Duration: 00:00 | DP | 2025-12-23 19:36:40The Ultimate Guide to Linux `rm` Command: How to Safely and Efficiently Delete Directories
Duration: 00:00 | DP | 2025-12-24 07:52:30Linux Command-Line Magic: 3 Ways to Instantly Truncate Large Files
Duration: 00:00 | DP | 2025-12-27 21:43:20Master Batch File Creation in Linux: 4 Efficient Command-Line Methods
Duration: 00:00 | DP | 2025-11-10 09:27:00Solved: `node` and `npm` Commands Not Recognized on Windows 10 After Node.js Installation
Duration: 00:00 | DP | 2025-11-14 14:15:00Recommended
The Ultimate Guide: Solving Google's 'HTTPS Invalid Certificate' Ghost Error When Local Tests Pass
00:00 | 34Ever faced the frustrating situation where Google ...
The Ultimate PHP Logging Guide: From a Messy Function to an Elegant Static Logger Class
00:00 | 4Logging is essential in any PHP project. However, ...
Master Batch File Creation in Linux: 4 Efficient Command-Line Methods
00:00 | 47Discover four powerful command-line methods for ba...
Shell Magic: How to Gracefully Write Output from Multiple Commands to a Single Log File
00:00 | 31In shell scripting or daily system administration,...