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:30Show 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:00Recommended
Mastering PHP Switch: How to Handle Multiple Conditions for a Single Case
00:00 | 10Have you ever tried to match multiple conditions i...
Vite's `?url` Import Explained: Bundled Code or a Standalone File?
00:00 | 10In a Vite project, when you use `import myFile fro...
Step-by-Step Guide to Fixing `net::ERR_SSL_PROTOCOL_ERROR` in Chrome for Local Nginx HTTPS Setup
00:00 | 13Struggling with the `net::ERR_SSL_PROTOCOL_ERROR` ...
“Claude Code requires Git Bash” Error on Windows? Here's the Easy Fix
00:00 | 355Encountering the "Claude Code on Windows requires ...