---
title: "How to Install Node.js using NVM on MacOS and Ubuntu"
description: "Step-by-step guide to installing Node.js via NVM on macOS and Ubuntu, including Apple Silicon Macs and switching between multiple Node versions."
date: 2026-06-27
categories: ["web-development"]
tags: ["node"]
---

import YouTubeEmbed from "../../components/widgets/YouTubeEmbed.astro";

NVM (Node Version Manager) is the recommended way to install Node.js on macOS and Linux. It lets you install multiple Node.js versions and switch between them without sudo. This guide covers installation on both macOS and Ubuntu, plus how to manage multiple Node versions.

## Why NVM instead of direct install

Installing Node.js directly from the official installer or your OS package manager works, but it has downsides:

- System packages are often outdated (Ubuntu's default repo can be months behind).
- You need `sudo` to install global npm packages, which is a permission headache.
- Switching between Node versions for different projects is painful.

NVM solves all three. Each Node version installs in your home directory (`~/.nvm/versions/node/`), and switching is instant.

## 1. Install NVM

### macOS

Make sure Xcode Command Line Tools are installed first:

```bash
xcode-select --install
```

Then install NVM using the official install script:

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

This clones NVM to `~/.nvm` and adds the necessary lines to your shell profile (`~/.zshrc` on modern macOS, since zsh is the default shell since macOS 10.15).

Reload your shell:

```bash
source ~/.zshrc
```

Verify it works:

```bash
nvm --version
```

You should see `0.40.5`.

**Note on Apple Silicon (M1/M2/M3/M4) Macs:** Node.js v16+ has native arm64 support, so NVM works out of the box. If you need to run Node.js versions older than v16, you'll need to use Rosetta — see the [NVM docs for Apple Silicon](https://github.com/nvm-sh/nvm#macs-with-apple-silicon-chips).

**Don't use Homebrew to install NVM.** The NVM maintainers explicitly say Homebrew installation is not supported. If you already have it installed via Homebrew, uninstall it first with `brew uninstall nvm` and use the script above.

### Ubuntu

Install curl if you don't have it:

```bash
sudo apt update && sudo apt install curl -y
```

Then run the official install script:

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

The script clones NVM to `~/.nvm` and adds the source lines to `~/.bashrc`. Reload your shell:

```bash
source ~/.bashrc
```

Verify:

```bash
nvm --version
```

That's it. No `sudo` needed, no system-level changes.

## YouTube walkthrough

<YouTubeEmbed
  url="https://www.youtube.com/embed/XXrZHWKTJfg"
  label="How to Install Node.js using NVM on MacOS and Ubuntu"
/>

## 2. Install Node.js with NVM

NVM works the same on macOS and Ubuntu from here on.

### Install the latest LTS version

The `--lts` flag installs the latest Long-Term Support release. As of mid-2026, that's Node.js 24 (codename Krypton):

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

Verify:

```bash
node --version
# v24.x.x
npm --version
```

### Install a specific version

```bash
nvm install 22
```

This installs the latest v22.x release (codename Jod, also LTS).

### Switch between versions

```bash
nvm use 24
nvm use 22
```

Check what's installed:

```bash
nvm ls
```

### Set a default version

The first version you install becomes the default for new shells. To change it:

```bash
nvm alias default 24
```

### Use a .nvmrc file (per-project Node version)

Create a `.nvmrc` file in your project root:

```bash
echo "22" > .nvmrc
```

Then when you `cd` into that project directory:

```bash
nvm use
# Found .nvmrc with version <22>
# Now using node v22.22.1
```

If the version isn't installed yet, `nvm install` will download it automatically.

## Current Node.js release schedule

| Version | Codename | Status | EOL |
|---------|----------|--------|-----|
| v26 | — | Current (May 2026) | — |
| v24 | Krypton | Active LTS | Apr 2028 |
| v22 | Jod | Maintenance LTS | Apr 2027 |
| v20 | Iron | EOL (Apr 2026) | — |
| v18 | Hydrogen | EOL (Apr 2025) | — |
| v16 | Gallium | EOL (Sep 2023) | — |

Use v24 for new projects. Use v22 if your project or dependencies haven't caught up yet. Avoid v20 and older.

Starting with Node.js 27 (October 2026), the release cycle moves to one major version per year instead of two.

## Useful NVM commands

| Command | What it does |
|---------|--------------|
| `nvm install --lts` | Install latest LTS |
| `nvm install 24` | Install specific major version |
| `nvm install 22.10.0` | Install exact version |
| `nvm use 24` | Switch to version |
| `nvm ls` | List installed versions |
| `nvm ls-remote --lts` | List all available LTS versions |
| `nvm alias default 24` | Set default for new shells |
| `nvm uninstall 18` | Remove a version |
| `nvm current` | Show active version |

## Troubleshooting

**`nvm: command not found` after install**

Your shell profile wasn't sourced. Try closing and reopening your terminal. If that doesn't work, check that `~/.zshrc` (macOS) or `~/.bashrc` (Ubuntu) contains the NVM lines. You can also run:

```bash
source ~/.nvm/nvm.sh
```

**npm global packages need sudo**

If you're using `sudo npm install -g <package>`, something is wrong. NVM-installed Node doesn't need sudo for global packages. If you have an `~/.npmrc` file with a `prefix` setting, remove it.

**Old Node version shows up after opening a new terminal**

Run `nvm alias default` to see what's set. Fix it with `nvm alias default <version>`.

**`which nvm` returns nothing**

That's expected. NVM is a shell function, not a binary. Use `command -v nvm` instead.