Skip to content

Guide · Open source

How to use n: install and switch Node.js versions

Updated · written with AI from the project's own documentation and checked against our catalogue data

n is a small command-line tool for installing Node.js and switching between versions. You give it a version such as 20 or lts, it downloads that version and makes it the active one. This guide shows you how to install n, install and switch Node.js versions, remove old ones, and run a specific version without changing your active install.

ntj/n · ★ 19.5k · MIT

Quick start

  1. 1Check that Node.js is installed. n is installed with npm, so you need an existing Node.js install first. If you have none, follow the README's curl bootstrap option.
  2. 2Install n globally. Run npm install -g n. If you get a permission error, change ownership of the directories, set N_PREFIX, or use sudo as described in the README.
  3. 3Install the latest LTS. Run n lts to download and activate the newest Long Term Support release.
  4. 4Open a new shell. If the active version has not changed, open a new terminal so you do not see a stale version.
  5. 5Switch versions. Run n followed by a version such as 20, or run n alone and pick from the interactive list.
  6. 6Pin versions per project. Add a .n-node-version, .node-version or .nvmrc file to the project and run n auto.

Install n on macOS, Linux or WSL

If you already have Node.js installed, the simplest way to install n is with npm. n is written as a Bash script, but you do not need Bash as your everyday shell.

The default install location is /usr/local, which a normal user often cannot write to. If you hit a permission error you have three options: change ownership of the relevant directories to yourself, tell n to use a custom location with N_PREFIX, or put sudo in front of the command.

  • Supported: macOS, Linux, Windows Subsystem for Linux and other unix-like systems.
  • Not supported: native Windows shells such as PowerShell, Git for Windows BASH, or the Cygwin DLL.
npm install -g n

Install the latest LTS version of Node.js

Run n with the label lts to download the newest Long Term Support release and make it the active version. If the version is already cached, n installs it from the cache.

If npm is not available yet, the README shows a way to bootstrap n with curl. Other options it lists are Homebrew (brew install n) and MacPorts (port install n).

n lts

Install and switch between Node.js versions

Run n followed by a version to download and install it. Numeric versions can be complete or partial, with an optional leading v. A partial version such as 8 uses the latest matching 8.x.y release.

Run n on its own to open an interactive list of downloaded versions. Use the arrow keys, or j and k, to select a version, press return to install it, d to delete it, and q to quit. If the active version does not change, open a new shell, because the old one may show a stale version.

  • 4.9.1 selects that exact version.
  • 8 selects the latest 8.x.y version.
  • v6.1 selects the latest 6.1.x version.
  • lts, latest and current are labels for the newest LTS, newest, and newest non-alpha releases.
n 10.16.0 n lts n

Use a version file in your project

The auto label reads the target version from a file in the current directory or a parent directory. n checks for .n-node-version first, then .node-version, then .nvmrc. If none of these exists, it looks at the engines or devEngines field in package.json, which requires jq or node to be installed.

Named release streams and other builds are also available, such as nightly and rc/10.

  • .n-node-version: a single-line version, custom to n
  • .node-version: a single-line version used by several tools
  • .nvmrc: a single-line version used by nvm
n auto

Remove cached versions

n caches downloaded versions, so switching back does not require another download. To free space, remove specific cached versions, remove all cached versions except the installed one, or remove the installed Node.js. Removing the installed version does not touch the cache.

n rm 0.9.4 v0.10.0 n prune n uninstall

Run a downloaded version without switching

You can use a cached version without making it active. n which prints the path to a cached node binary. n run starts a cached version with arguments. n exec changes PATH for one command, so node and npm come from the chosen version. Note that npm run this way uses global modules from that version's folder.

n which 6.14.3 n run 8.11.3 --debug some.js n exec 10 my-script --fast test

What people use it for

  • Keep one project on Node 8 and another on the latest LTS, switching with n <version>.
  • Use n auto so a project's version file picks the Node.js version when you enter the folder.
  • Test a script against an older release with n run or n exec without changing your default.
  • Remove old cached versions with n prune to free disk space.
  • Keep a minimal setup on macOS or Linux with no shell profile changes.

Frequently asked questions

How do I install n?

If you already have Node.js, run npm install -g n. The README also lists Homebrew (brew install n) and MacPorts (port install n) on macOS. Then run n lts to install the latest LTS Node.js.

Does n work on Windows?

n works on Windows Subsystem for Linux. The README says it does not work in native Windows shells such as PowerShell, or in Git for Windows BASH.

Is n free?

n is open source under the MIT licence, as shown in the project's metadata.

Why do I get a permission error when installing n?

The default root location, /usr/local, is usually not writable by a normal user. You can change ownership of the relevant directories, set N_PREFIX to a folder you can write to, or run the command with sudo.

Why does my shell still show the old Node.js version?

The README suggests opening a new shell if the active version does not change after install, because the old shell may show a stale version.

How does n compare to nvm, fnm and volta?

n is a minimal tool for Node.js only, with no shell subshells and no profile setup, and it has an interactive version picker. nvm, fnm and volta are comparable projects. This guide does not compare their features in detail, so check each project's documentation for specifics.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

n suits developers on macOS, Linux or WSL who want a minimal, Node.js-only tool with no shell profile changes and an interactive picker. If you use Windows PowerShell or Git for Windows BASH, or need one tool for many languages, pick another option such as nvm, fnm or volta.

Install options & downloads