---
title: "Install Node.js with nvm and switch versions step by step | Daniel Segovia"
description: "Install Node.js with nvm on Linux, macOS, and Windows. I'll show you how to install LTS, set a default version, and use .nvmrc per project."
url: https://danielsegovia.com/en/tutorials/install-nodejs-nvm-switch-version/
lang: en
author: "Daniel Segovia"
published: 2026-11-25T02:43:00.000Z
modified: 2026-11-25T02:33:37.481Z
section: "Tutorials"
---

1.  [Home](https://danielsegovia.com/en/)
2.  [Tutorials](https://danielsegovia.com/en/tutorials/)
3.  Install Node.js with nvm and switch versions step by step

# Install Node.js with nvm and switch versions step by step

[Tutorials](https://danielsegovia.com/en/tutorials/) By [Daniel Segovia](https://danielsegovia.com/en/about/) · November 24, 2026 · 5 min read

Install Node.js with nvm on Linux, macOS, and Windows. I'll show you how to install LTS, set a default version, and use .nvmrc per project.

In this post

1.  [Requirements to install Node.js with nvm](#requirements-to-install-node-js-with-nvm)
2.  [Step 1: install the version manager](#step-1-install-the-version-manager)
3.  [Step 2: install Node.js LTS](#step-2-install-node-js-lts)
4.  [Step 3: set a default version](#step-3-set-a-default-version)
5.  [Step 4: use a project-specific version with .nvmrc](#step-4-use-a-project-specific-version-with-nvmrc)
6.  [Step 5: align your package manager with Corepack (optional but useful)](#step-5-align-your-package-manager-with-corepack-optional-but)
7.  [Verify it worked](#verify-it-worked)
8.  [Common errors and how to fix them](#common-errors-and-how-to-fix-them)
9.  [FAQ](#faq)
10.  [Field note](#field-note)

Install Node.js with nvm is the safest way to run multiple versions without wrecking your machine. In this guide you'll install nvm, grab the LTS release of Node, set a default version, and configure .nvmrc so each project uses the right one. Copy, paste, done.

## Requirements to install Node.js with nvm

-   Linux, macOS, or WSL2 on Windows (for nvm). On native Windows we'll use nvm-windows.
-   Internet access and a terminal.
-   On Linux/macOS: `curl` or `wget`, and permission to edit your shell profile (`~/.bashrc`, `~/.zshrc`, etc.).
-   On Windows 10/11: have `winget` or `choco` available.

## Step 1: install the version manager

First we install the tool that manages Node versions. On Linux/macOS/WSL use nvm; on native Windows, nvm-windows.

### Linux/macOS/WSL: install nvm

With curl:

```bash
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
```

With wget:

```bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
```

Load nvm into your current shell without restarting:

```bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
```

If nvm doesn't load after reopening the terminal, add these lines to your profile. For Bash:

```bash
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' >> ~/.bashrc
```

For Zsh:

```bash
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.zshrc
echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' >> ~/.zshrc
```

### Windows: install nvm-windows

With winget:

```powershell
winget install -e --id CoreyButler.NVMforWindows
```

Or Chocolatey:

```powershell
choco install nvm -y
```

Close and reopen your terminal. Pro tip: use Windows Terminal and open a brand new window, not a tab from the old session.

## Step 2: install Node.js LTS

LTS is what you want for most cases. Stable, longer support, fewer surprises.

### Linux/macOS/WSL

List available LTS versions and pick one if you want to be explicit:

```bash
nvm ls-remote --lts
```

Install and use the latest LTS:

```bash
nvm install --lts
nvm use --lts
```

### Windows

List available versions, identify the current LTS, and replace the example below with that number:

```powershell
nvm list available
```

Install and activate the current LTS. Replace 20.18.1 with the LTS you saw:

```powershell
nvm install 20.18.1
nvm use 20.18.1
```

Note: the version number is an example. Use the LTS shown by your list.

## Step 3: set a default version

So every new shell starts with something sane.

### Linux/macOS/WSL

```bash
nvm alias default lts/*
```

### Windows

Pick the version you want as default. Again, replace with your LTS:

```powershell
nvm use 20.18.1
```

On nvm-windows, the version you use becomes the default for new terminals.

## Step 4: use a project-specific version with .nvmrc

This is the clean way to work. Declare in the repo which Node version the project expects. Less arguing, more shipping.

From your project root, create `.nvmrc` with the exact version (better than an alias) and activate it:

```bash
cd MY_PROJECT
echo "20.18.1" > .nvmrc
nvm use
```

On Windows, read the file and pass it to nvm:

```powershell
cd MY_PROJECT
type .nvmrc
nvm use (Get-Content .nvmrc)
```

Tip: commit `.nvmrc` to the repo. Your teammates (and CI) will thank you.

## Step 5: align your package manager with Corepack (optional but useful)

If you use Yarn or pnpm, enable Corepack so the project sticks to the declared version automatically.

```bash
corepack enable
```

If you want to pin a specific version per project:

```bash
corepack prepare yarn@stable --activate
corepack prepare pnpm@latest --activate
```

Then in `package.json` you can declare `packageManager` with its version. Clones will pick it up automatically.

## Verify it worked

Test Node and npm. On Linux/macOS/WSL:

```bash
node -v
npm -v
```

On Windows:

```powershell
node -v
npm -v
```

Expected output (example):

```text
v20.18.1
10.8.2
```

If you like checking paths: on Linux/macOS/WSL

```bash
which node
```

On Windows:

```powershell
where node
```

## Common errors and how to fix them

-   `nvm: command not found` on Linux/macOS/WSL
    
    Fix: your shell isn't loading nvm. Run:
    
    ```bash
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
    ```
    
    If that works, append it to `~/.bashrc` or `~/.zshrc` as shown earlier and reopen the terminal.
    
-   `N/A: version "X.Y.Z" is not yet installed` when running `nvm use`
    
    Fix: install that version first. For example:
    
    ```bash
    nvm install 20.18.1
    nvm use 20.18.1
    ```
    
-   Windows: `'node' is not recognized as an internal or external command`
    
    Fix: run `nvm use <version>` in a fresh terminal after installing. If it persists, close all terminals, reopen, check `where node`, and verify the version is installed with `nvm list`.
    
-   Windows: `Access is denied.` or issues switching versions
    
    Fix: close processes using Node (dev servers, IDEs). If needed, kill them:
    
    ```powershell
    taskkill /F /IM node.exe
    ```
    
    Try again and, if needed, run the terminal as Administrator and execute `nvm use <version>`.
    

## FAQ

### Should I use LTS or Current

For production and teams, LTS. It's stable and supported longer. Use Current only if you need bleeding-edge features and accept the risk.

### How do I upgrade to a new LTS without breaking projects

Install the new LTS and set it as default. Keep `.nvmrc` pinned per repo to the version you've validated. Your system gets the latest LTS, each repo stays put until you update it.

### Is it a good idea to put `lts/*` in `.nvmrc`

I don't recommend it. Use an exact number to avoid inconsistent builds the day LTS changes.

### Will it break if I also have a system-installed Node

It can. PATH conflicts are common. My advice: remove system/Homebrew Node and let nvm handle everything.

### How do I uninstall a version I no longer need

Easy. On Linux/macOS/WSL:

```bash
nvm uninstall 18.19.1
```

On Windows:

```powershell
nvm uninstall 18.19.1
```

## Field note

Two habits that saved me hours: 1) commit `.nvmrc`, 2) don't mix system Node with nvm. And when a build goes sideways, take a breath, run `nvm use` at the repo root, and move on.

## Tags

-   [#Node.js](https://danielsegovia.com/en/tags/node-js/)
-   [#nvm](https://danielsegovia.com/en/tags/nvm/)
-   [#Windows](https://danielsegovia.com/en/tags/windows/)
-   [#macOS](https://danielsegovia.com/en/tags/macos/)

[See all tags →](https://danielsegovia.com/en/tags/)

## Related posts

-   [How to create a TypeScript Lambda with AWS SAM](https://danielsegovia.com/en/tutorials/create-typescript-lambda-aws-sam/)
    
    How to create a TypeScript Lambda with AWS SAM. Initialize the project, compile with esbuild, test locally, and deploy to AWS in minutes without pain.
    
    5 min read
-   [Invoke Amazon Bedrock from Node.js: step-by-step guide](https://danielsegovia.com/en/tutorials/invoke-amazon-bedrock-nodejs/)
    
    Invoke Amazon Bedrock from Node.js using SDK v3. Set up IAM, call the Converse API, and handle throttling so your app doesn’t faceplant under load.
    
    6 min read
-   [Create an MCP server in TypeScript: step-by-step guide](https://danielsegovia.com/en/tutorials/create-mcp-server-typescript/)
    
    Learn how to create an MCP server in TypeScript, expose tools and resources with the official SDK, and test it with a compatible client.
    
    6 min read

## More categories

-   ### [Tutorials](https://danielsegovia.com/en/tutorials/)
    
    [How to create a TypeScript Lambda with AWS SAM](https://danielsegovia.com/en/tutorials/create-typescript-lambda-aws-sam/)
    
    How to create a TypeScript Lambda with AWS SAM. Initialize the project, compile with esbuild, test locally, and deploy to AWS in minutes without pain.
    
    New 5 min read
    
-   ### [News](https://danielsegovia.com/en/news/)
    
    [Huawei speeds chip design; Nvidia slows ASEAN server flows](https://danielsegovia.com/en/news/huawei-speeds-chip-design-nvidia-slows-asean-servers/)
    
    Huawei pushes its homegrown chip-design stack while Nvidia halts AI server shipments in ASEAN. If you bet on one vendor, map risk and ship a plan B.
    
    New 3 min read
    
-   ### [Artificial Intelligence](https://danielsegovia.com/en/artificial-intelligence/)
    
    [OpenAI/Anthropic lock data; China turns to Google and Meta](https://danielsegovia.com/en/artificial-intelligence/openai-anthropic-lock-data-china-google-meta/)
    
    OpenAI and Anthropic restricted data and Chinese players look to Google and Meta. Time to harden pipelines: clear licenses and a data plan B.
    
    New 3 min read
    
-   ### [Security](https://danielsegovia.com/en/security/)
    
    [GoodGuys phishing mimics brands to steal Google/Okta](https://danielsegovia.com/en/security/goodguys-phishing-google-okta-paid-interviews/)
    
    GoodGuys lures with paid interviews to steal corporate Google/Okta creds. Active since October. Priorities: FIDO MFA, phishing drills, and tight SSO control.
    
    New 3 min read
    
-   ### [Architecture](https://danielsegovia.com/en/architecture/)
    
    [Cloudflare toggle for AI-agent search, and you pay the bill](https://danielsegovia.com/en/architecture/cloudflare-toggle-ai-agent-search-cost-privacy/)
    
    Cloudflare added a toggle for AI agents to search your site. You pay the query bill. Good DX, new risks to budgets and privacy. Add access controls and limits.
    
    New 3 min read
    
-   ### [Business](https://danielsegovia.com/en/business/)
    
    [AI infrastructure spend could hit $1T in 2026: now what](https://danielsegovia.com/en/business/ai-infrastructure-spend-2026-1t/)
    
    AI infra investment could reach $1T in 2026. With a $1.8T funding gap through 2030, it’s time to lock budgets, renegotiate contracts and squeeze unit costs.
    
    New 3 min read

---

Sitio: https://danielsegovia.com/ · Índice para agentes: https://danielsegovia.com/llms.txt · Sitemap: https://danielsegovia.com/sitemap.xml
