n – Node.js Version Manager
n is a command-line interface (CLI) tool designed for interactively managing Node.js versions on Unix-like systems, including macOS and Linux (with WSL support). It distinguishes itself from alternatives like nvm by avoiding subshells and complex profile setups, offering a simple and direct approach to switching Node.js environments. The current stable version is 10.2.0, with minor and patch releases occurring every few weeks to months, and major versions less frequently, typically driven by significant internal changes or feature additions. Key differentiators include its simplicity, direct control over installed Node.js binaries, and a lack of shell modification, making it a straightforward choice for developers who prefer minimal environmental interference. It caches Node.js versions locally and allows for quick installation and activation of different versions.
Common errors
-
EACCES: permission denied, mkdir '/usr/local/n'
cause Attempting to install 'n' or Node.js versions into system directories without sufficient permissions.fixUse `sudo npm install -g n` or `sudo n <version>`, or adjust directory ownership with `sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share`. -
n: command not found
cause 'n' executable is not in your system's PATH environment variable after installation.fixEnsure the directory where 'n' was installed (e.g., `/usr/local/bin` or a custom `N_PREFIX` location) is correctly included in your shell's PATH. Restart your terminal session after installation. -
npm: command not found
cause The npm binary associated with the currently active Node.js version is not in your PATH or was not properly installed with the Node.js version.fixVerify that a Node.js version is active using `n ls`. If npm is missing, you might need to reinstall the Node.js version (`n install <version>`) or check for conflicting npm installations using `n doctor`. -
curl: (3) URL using bad/illegal format or missing URL
cause This error can occur if `curl` has issues with specific options or if the download URL generated by `n` is malformed or inaccessible (e.g., due to network issues, or specific `curl` versions).fixCheck your network connectivity. If persistent, try updating `curl` to its latest version. In some cases, `n` might be sensitive to older `curl` versions (e.g., issues with `--compressed` in `curl` 8.7.1 were fixed in `n` v9.2.3). Ensure there are no proxy issues interfering with downloads.
Warnings
- breaking Starting with v10.0.0, 'n' can optionally use `jq` for reading `engines` from `package.json` files, improving performance and robustness. While it falls back to Node.js if `jq` is absent, its presence might be assumed or preferred for optimal operation, potentially leading to slight behavioral changes for users without `jq` installed.
- breaking In v9.0.0, the `--preserve` option now also preserves `corepack` by default. This alters previous behavior where `corepack` might not have been preserved during Node.js version switches, potentially affecting workflows that rely on specific `corepack` configurations.
- gotcha 'n' does not officially support native Microsoft Windows shells (like PowerShell or CMD), nor Git for Windows BASH or Cygwin. It is designed for macOS, Linux, and other Unix-like systems, including Windows Subsystem for Linux (WSL).
- gotcha The default installation location for 'n' is typically `/usr/local`, which often requires superuser (sudo) permissions for installation and managing Node.js versions. Installing without correct permissions can lead to `EACCES` errors.
- gotcha During `n install` operations, especially after `npm install -g n`, it's possible for multiple `npm` installations to exist on the system if previous Node.js installations were done manually or via other managers. This can lead to unexpected behavior or `npm` not being found after a version switch.
Install
-
npm install n -
yarn add n -
pnpm add n
Quickstart
# Install n globally using npm (requires Node.js to be pre-installed or n to be bootstrapped first) npm install -g n # Or, bootstrap install if npm/Node.js is not yet available, then install n # curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s install lts # npm install -g n # Install the latest LTS (Long Term Support) version of Node.js n lts # Install a specific Node.js version (e.g., 18.17.1) n 18.17.1 # Switch to a specific Node.js version interactively n # Use arrow keys to select and Enter to activate # Run a command with a specific Node.js version without changing the global default n use 18.17.1 my-script.js # See currently installed Node.js versions and the active one n ls # Remove a specific Node.js version n rm 14.17.6 # Clean up cached versions not currently in use n prune # Install the latest stable version of Node.js n latest