tj /n

Node version management

★ 19,515⑂ 759
ShellCreated 2011-01-05
19,515
stars
+4+5+2
759
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions

README

n – Interactively Manage Your Node.js Versions






Node.js version management: no subshells, no profile setup, no convoluted API, just simple.

!usage animation

- n – Interactively Manage Your Node.js Versions
  - Supported Platforms
  - Installation
    - Third Party Installers
    - Replacing a previous node install
  - Installing Node.js Versions
  - Specifying Node.js Versions
  - Removing Versions
  - Using Downloaded Node.js Versions Without Reinstalling
  - Preserving npm
  - Miscellaneous
  - Custom Mirror
  - Custom Architecture
  - Optional Environment Variables
  - How It Works

 Supported Platforms

n is supported on macOS, Linux, including with Windows Subsystem for Linux, and various other unix-like systems.
It is written as a BASH script but does not require you to use BASH as your command shell.

n does not work in native shells on Microsoft Windows (like PowerShell), or Git for Windows BASH, or with the Cygwin DLL.

 Installation

If you already have Node.js installed, an easy way to install n is using npm:

    npm install -g n

The default root location used when running n is /usr/local where a normal user does not have write permission. You may strike the same sort of permission error when using npm to install global modules, like the above command. You have three main options:

1) change the ownership of the relevant directories to yourself (see below)
2) tell n to use a custom location where you do have write permissions (see N_PREFIX)
3) put sudo in front of the command to run it as super user

n caches Node.js versions in subdirectory n/versions. The _active_ Node.js version is installed in subdirectories bin, include, lib, and share.

To take ownership of the system directories (option 1):

     make cache folder (if missing) and take ownership
    sudo mkdir -p /usr/local/n
    sudo chown -R $(whoami) /usr/local/n
     make sure the required folders exist (safe to execute even if they already exist)
    sudo mkdir -p /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share
     take ownership of Node.js install destination folders
    sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share

-----

If npm is not yet available, one way to bootstrap an install is to download and run n directly. To install the lts version of Node.js:

    curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s install lts
     If you want n installed, you can use npm now.
    npm install -g n

If you don't need support for updates to n itself you can just save the download:

    curl -fsSL -o /usr/local/bin/n https://raw.githubusercontent.com/tj/n/master/bin/n 
    chmod 0755 /usr/local/bin/n
    n install lts

 Third Party Installers

On macOS with Homebrew you can install the n formula.

    brew install n

Or on macOS with MacPorts you can install the n port:

    port install n

On Linux and macOS, n-install allows installation directly from GitHub; for instance:

    curl -L

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON