2016-06-16 02:17:38 +02:00
# `n` – Interactively Manage Your Node.js Versions
2011-01-05 16:01:29 +01:00
2015-12-27 05:29:15 +01:00
[![npm ](https://img.shields.io/npm/dt/n.svg?style=flat-square )](https://www.npmjs.com/package/n)
[![npm ](https://img.shields.io/npm/dm/n.svg?style=flat-square )](https://www.npmjs.com/package/n)
[![npm ](https://img.shields.io/npm/v/n.svg?style=flat-square )](https://www.npmjs.com/package/n)
[![npm ](https://img.shields.io/npm/l/n.svg?style=flat-square )](https://www.npmjs.com/package/n)
2015-05-08 15:55:59 +02:00
2016-06-16 02:17:38 +02:00
Node.js version management: no subshells, no profile setup, no convoluted API, just **simple** .
2011-01-05 16:01:29 +01:00
2019-04-07 07:23:31 +02:00
![usage animation ](http://nimit.io/images/n/n.gif )
2013-08-28 05:08:43 +02:00
2019-04-07 07:23:31 +02:00
(Note: `n` is not supported natively on Windows.)
2016-07-05 09:15:09 +02:00
2019-08-03 09:54:26 +02:00
- [`n` – Interactively Manage Your Node.js Versions ](#n-%e2%80%93-interactively-manage-your-nodejs-versions )
- [Installation ](#installation )
- [Third Party Installers ](#third-party-installers )
- [Installing Node Versions ](#installing-node-versions )
- [Specifying Node Versions ](#specifying-node-versions )
- [Removing Versions ](#removing-versions )
- [Using Downloaded Node Versions Without Reinstalling ](#using-downloaded-node-versions-without-reinstalling )
- [Miscellaneous ](#miscellaneous )
- [Custom Source ](#custom-source )
- [Custom Architecture ](#custom-architecture )
- [Optional Environment Variables ](#optional-environment-variables )
2017-10-23 07:26:37 +02:00
2011-01-05 16:01:29 +01:00
## Installation
2016-06-16 02:17:38 +02:00
Since you probably already have `node` , the easiest way to install `n` is through `npm` :
2015-07-20 15:43:48 +02:00
2019-04-07 07:23:31 +02:00
npm install -g n
2011-01-05 16:01:29 +01:00
2016-06-16 02:17:38 +02:00
Alternatively, you can clone this repo and
2011-01-05 16:01:29 +01:00
2019-04-07 07:23:31 +02:00
make install
2015-05-07 16:40:23 +02:00
2016-06-16 02:17:38 +02:00
to install `n` to `bin/n` of the directory specified in the environment variable `$PREFIX` , which defaults to `/usr/local` (note that you will likely need to use `sudo` ). To install `n` in a custom location (such as `$CUSTOM_LOCATION/bin/n` ), run `PREFIX=$CUSTOM_LOCATION make install` .
2015-07-20 19:03:00 +02:00
2019-06-02 10:15:50 +02:00
Once installed, `n` caches `node` versions in subdirectory `n/versions` of the directory specified in environment variable `N_PREFIX` , which defaults to `/usr/local` ; and the _active_ `node` version is installed directly in `N_PREFIX` .
2014-02-11 17:30:08 +01:00
2019-08-03 09:54:26 +02:00
To avoid requiring `sudo` for `n` and `npm` global installs, it is suggested you either install to your home directory using `N_PREFIX` , or take ownership of the system directories:
2019-04-07 06:54:02 +02:00
2019-08-03 09:54:26 +02:00
# make cache folder (if missing) and take ownership
sudo mkdir -p /usr/local/n
sudo chown -R $(whoami) /usr/local/n
# take ownership of node install destination folders
sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share
2019-04-07 06:54:02 +02:00
2019-03-31 11:00:09 +02:00
### Third Party Installers
2019-04-21 02:43:51 +02:00
On macOS with [Homebrew ](https://brew.sh/ ) you can install the [n formula ](https://github.com/Homebrew/homebrew-core/blob/master/Formula/n.rb ).
2018-10-28 09:48:56 +01:00
brew install n
2019-03-31 11:00:09 +02:00
On Linux and macOS, [n-install ](https://github.com/mklement0/n-install ) allows installation directly from GitHub; for instance:
2015-07-20 15:43:48 +02:00
2016-09-21 00:11:00 +02:00
curl -L https://git.io/n-install | bash
2015-07-20 15:43:48 +02:00
2019-05-05 00:17:11 +02:00
n-install sets both `PREFIX` and `N_PREFIX` to `$HOME/n` , installs `n` to `$HOME/n/bin` , modifies the initialization files of supported shells to export `N_PREFIX` and add `$HOME/n/bin` to the `PATH` , and installs the latest LTS `node` version.
2016-06-16 02:17:38 +02:00
As a result, both `n` itself and all `node` versions it manages are hosted inside a single, optionally configurable directory, which you can later remove with the included `n-uninstall` script. `n-update` updates `n` itself to the latest version. See the [n-install repo ](https://github.com/mklement0/n-install ) for more details.
2011-01-05 16:48:51 +01:00
2019-08-03 09:54:26 +02:00
## Installing Node Versions
2016-06-16 02:17:38 +02:00
2019-08-03 09:54:26 +02:00
Simply execute `n <version>` to download and install a version of `node` . If `<version>` has already been downloaded, `n` will install from its cache.
2011-01-05 16:48:51 +01:00
2019-08-03 09:54:26 +02:00
n 10.16.0
n lts
2011-01-05 16:48:51 +01:00
2019-08-03 09:54:26 +02:00
Execute `n` on its own to view your downloaded versions, and install the selected version.
2011-01-05 16:48:51 +01:00
$ n
2011-10-26 22:59:40 +02:00
2019-01-13 03:35:56 +01:00
node/4.9.1
ο node/8.11.3
node/10.15.0
2011-01-05 16:48:51 +01:00
2019-08-03 09:54:26 +02:00
Use up/down arrow keys to select a version, return key to install, q to quit
2011-01-22 00:25:07 +01:00
2019-08-03 09:54:26 +02:00
(You can also use `j` and `k` to navigate up or down without using arrows.)
2012-01-25 12:42:27 +01:00
2019-08-03 09:54:26 +02:00
If the active node version does not change after install, try opening a new shell in case seeing a stale version.
2015-11-05 04:08:42 +01:00
2019-08-03 09:54:26 +02:00
## Specifying Node Versions
There are a variety of ways of specifying the target node version for `n` commands. Most commands use the latest matching version, and `n ls-remote` lists multiple matching versions.
Numeric version numbers can be complete or incomplete, with an optional leading `v` .
- `4.9.1`
- `8` : 8.x.y versions
- `v6.1` : 6.1.x versions
There are labels for two especially useful versions:
2015-11-05 04:08:42 +01:00
2019-08-03 09:54:26 +02:00
- `lts` : newest Long Term Support official release
- `latest` , `current` : newest official release
There is support for release streams:
- `argon` , `boron` , `carbon` : codenames for LTS release streams
The last form is for specifying [other releases ](https://nodejs.org/download ) available using the name of the remote download folder optionally followed by the complete or incomplete version.
- `chakracore-release/latest`
- `nightly`
- `test/v11.0.0-test20180528`
- `rc/10`
2019-06-03 11:27:18 +02:00
2019-03-31 11:00:09 +02:00
## Removing Versions
2011-01-05 16:55:56 +01:00
2019-05-09 12:22:17 +02:00
Remove some cached versions:
2011-01-05 17:17:16 +01:00
2019-04-07 07:23:31 +02:00
n rm 0.9.4 v0.10.0
2011-01-05 17:23:02 +01:00
2019-05-09 12:22:17 +02:00
Removing all cached versions except the current version:
2017-04-12 15:10:25 +02:00
2019-04-07 07:23:31 +02:00
n prune
2017-04-12 15:10:25 +02:00
2019-05-09 12:22:17 +02:00
Remove the installed node and npm (does not affect the cached version). This can be useful
to revert to the system version of node (if in a different location), or if you no longer
2019-05-10 10:20:34 +02:00
wish to use node and npm, or are switching to a different way of managing them.
2019-05-09 12:22:17 +02:00
n uninstall
2019-08-03 09:54:26 +02:00
## Using Downloaded Node Versions Without Reinstalling
2011-01-05 17:43:16 +01:00
2019-08-03 09:54:26 +02:00
There are three commands for working directly with your downloaded versions of `node` , without reinstalling.
2011-01-05 17:43:16 +01:00
2019-08-03 09:54:26 +02:00
You can show the path to the downloaded version:
2011-01-05 16:01:29 +01:00
2019-08-03 09:54:26 +02:00
$ n which 6.14.3
/usr/local/n/versions/6.14.3/bin/node
2011-01-05 16:01:29 +01:00
2019-08-03 09:54:26 +02:00
Or run a downloaded `node` version with the `n run` command:
2011-01-05 17:17:16 +01:00
2019-08-03 09:54:26 +02:00
n run 8.11.3 --debug some.js
2011-01-05 16:01:29 +01:00
2019-08-03 09:54:26 +02:00
Or execute a command with `PATH` modified so `node` and `npm` will be from the downloaded `node` version.
(NB: this `npm` will be working with a different and empty global node_modules directory, and you should not install global
modules this way.)
2011-01-05 16:01:29 +01:00
2019-08-03 09:54:26 +02:00
n exec 10 my-script --fast test
2015-05-07 16:40:23 +02:00
2019-08-03 09:54:26 +02:00
## Miscellaneous
2011-01-05 16:01:29 +01:00
2019-08-03 09:54:26 +02:00
Command line help can be obtained from `n --help` .
2013-01-18 16:41:51 +01:00
2019-08-03 09:54:26 +02:00
List matching remote versions available for download:
2013-01-18 16:41:51 +01:00
2019-08-03 09:54:26 +02:00
n ls-remote lts
n ls-remote latest
n lsr 10
n --all lsr
2013-01-18 16:41:51 +01:00
2019-08-03 09:54:26 +02:00
List downloaded versions in cache:
2013-01-18 16:41:51 +01:00
2019-08-11 22:23:28 +02:00
n ls
2013-01-18 16:41:51 +01:00
2019-08-03 09:54:26 +02:00
Display diagnostics to help resolve problems:
2013-01-18 16:41:51 +01:00
2019-08-11 22:23:28 +02:00
n doctor
2011-01-22 00:25:07 +01:00
2019-06-02 10:15:50 +02:00
## Custom Source
2015-08-28 23:18:25 +02:00
2019-08-03 09:54:26 +02:00
If you would like to use a different node mirror which has the same layout as the default < https: // nodejs . org / dist /> , you can define `N_NODE_MIRROR` .
2019-05-09 11:29:32 +02:00
The most common example is users in China can define:
2015-08-28 23:18:25 +02:00
2019-08-03 09:54:26 +02:00
export N_NODE_MIRROR=https://npm.taobao.org/mirrors/node
There is also `N_NODE_DOWNLOAD_MIRROR` for a different mirror with same layout as the default < https: // nodejs . org / download >
2015-08-28 23:18:25 +02:00
2019-06-02 10:15:50 +02:00
## Custom Architecture
2015-08-30 12:27:35 +02:00
By default `n` picks the binaries matching your system architecture, e.g. `n` will download 64 bit binaries for a 64 bit system. You can override this by using the `-a` or `--arch` option.
2016-06-16 02:17:38 +02:00
Download and use latest 32 bit version of `node` :
2015-08-30 12:27:35 +02:00
2019-04-07 07:23:31 +02:00
n --arch x86 latest
2015-08-30 12:27:35 +02:00
2019-06-02 10:15:50 +02:00
## Optional Environment Variables
2016-06-16 02:17:38 +02:00
2019-06-02 10:15:50 +02:00
The `n` command downloads and installs to `/usr/local` by default, but you may override this location by defining `N_PREFIX` .
To change the location to say `$HOME/.n` , add lines like the following to your shell initialization file:
2016-06-16 02:17:38 +02:00
2019-06-02 10:15:50 +02:00
export N_PREFIX=$HOME/.n
export PATH=$N_PREFIX/bin:$PATH
2016-06-16 02:17:38 +02:00
2019-07-20 03:17:16 +02:00
By default `n` downloads archives from the mirror site which have been compressed with `gzip` . You can switch to using the `xz` compressed archives by defining `N_USE_XZ` .
export N_USE_XZ=true
2019-06-02 10:15:50 +02:00
In brief:
2019-07-20 03:17:16 +02:00
2019-08-03 09:54:26 +02:00
- `N_NODE_MIRROR` : See [Custom source ](#custom-source )
- `N_NODE_DOWNLOAD_MIRROR` : See [Custom source ](#custom-source )
2019-06-02 10:15:50 +02:00
- support for [NO_COLOR ](http://no-color.org ) and [CLICOLOR=0 ](https://bixense.com/clicolors ) for controlling use of ANSI color codes
2019-08-03 09:54:26 +02:00
- `N_MAX_REMOTE_MATCHES` to change the default `ls-remote` maximum of 20 matching versions