# How to Manage Node.js Versions with NVM: Listing and Switching Versions

> Author: [Oussama Ghaieb](https://oussama.ghaieb.com/about-me)
> Canonical: https://oussama.ghaieb.com/posts/how-to-manage-node-js-versions-with-nvm-listing-and-switching-versions

# <span class="hover:bg-yellow-100">How to Manage Node.js Versions with NVM: Listing and Switching Versions</span>

If you work with Node.js—whether you're a developer, a DevOps engineer, or just someone experimenting with JavaScript—you've likely encountered situations where you need to switch between different versions of Node.js for various projects. **nvm (Node Version Manager)** is a powerful tool that makes this process seamless. In this blog post, we'll walk you through how to list installed Node.js versions, switch between them, and set a default version using `nvm`.

---

## What is NVM?

**nvm** is a version manager for Node.js that allows you to install, manage, and switch between multiple versions of Node.js on your machine. It’s especially useful when working on multiple projects that require different Node.js versions.

---

## Installing NVM

If you haven’t installed `nvm` yet, you can do so by following the official installation instructions for your operating system:

- **macOS/Linux**: Use the [nvm installation script](https://github.com/nvm-sh/nvm#installing-and-updating).
- **Windows**: Use [nvm-windows](https://github.com/coreybutler/nvm-windows).

Once installed, you’re ready to start managing your Node.js versions!

---

## Listing Installed Node.js Versions

To see all the Node.js versions installed on your system using `nvm`, run the following command:

```bash
nvm ls
```

This will display a list of installed Node.js versions. The currently active version will be highlighted with an arrow (`->`), and the default version (if set) will be marked with `default`.

**Example Output:**

```
       v14.17.0
->     v16.13.0
        v18.0.0
default -> 16.13.0 (-> v16.13.0)
```

In this example:
- `v16.13.0` is the currently active version.
- `v14.17.0` and `v18.0.0` are also installed but not active.
- The default version is set to `v16.13.0`.

---

## Switching Between Node.js Versions

To switch to a specific Node.js version, use the `nvm use` command followed by the version number:

```bash
nvm use <version>
```

For example, to switch to Node.js version `16.13.0`, run:

```bash
nvm use 16.13.0
```

After running this command, your terminal will use the specified version of Node.js.

---

## Setting a Default Node.js Version

If you want a specific version of Node.js to be the default every time you open a new terminal, you can set it using the `nvm alias` command:

```bash
nvm alias default <version>
```

For example, to set `v16.13.0` as the default version, run:

```bash
nvm alias default 16.13.0
```

Now, every time you open a new terminal, `nvm` will automatically use the specified version.

---

## Installing a New Node.js Version

If the version you need isn’t already installed, you can easily install it using `nvm`. To install a specific version, run:

```bash
nvm install <version>
```

For example, to install Node.js version `18.0.0`, run:

```bash
nvm install 18.0.0
```

Once installed, you can switch to it using the `nvm use` command.

---

## Listing Available Node.js Versions

To see all the Node.js versions available for installation, use the `nvm ls-remote` command:

```bash
nvm ls-remote
```

This will display a long list of all available Node.js versions. You can scroll through the list to find the version you need.

---

## Summary of Commands

Here’s a quick reference for the most commonly used `nvm` commands:

<table>
  <thead>
    <tr>
      <th>Command</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>nvm ls</code></td>
      <td>List installed Node.js versions.</td>
    </tr>
    <tr>
      <td><code>nvm use &lt;version&gt;</code></td>
      <td>Switch to a specific Node.js version.</td>
    </tr>
    <tr>
      <td><code>nvm alias default &lt;version&gt;</code></td>
      <td>Set a default Node.js version.</td>
    </tr>
    <tr>
      <td><code>nvm install &lt;version&gt;</code></td>
      <td>Install a specific Node.js version.</td>
    </tr>
    <tr>
      <td><code>nvm ls-remote</code></td>
      <td>List all available Node.js versions for install.</td>
    </tr>
  </tbody>
</table>

---

## Conclusion

Using `nvm` to manage Node.js versions is a game-changer for developers. It simplifies the process of switching between versions, ensures compatibility across projects, and eliminates version conflicts. Whether you're working on a legacy project that requires an older version of Node.js or experimenting with the latest features, `nvm` has you covered.

Start using `nvm` today and take control of your Node.js environment! If you have any questions or need further assistance, feel free to leave a comment below.

Happy coding! 🚀
