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`.
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:
If `npm` is not yet available, one way to bootstrap an install:
curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n
bash n lts
# Now node and npm are available
Alternatively, you can clone this repo and
make install
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`.
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.
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.
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:
-`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.
A `node` install normally includes `npm` as well, but you may wish to preserve an updated `npm` and `npx` leaving them out of the install using `--preserve` (requires rsync):
$ npm install -g npm@latest
...
$ npm --version
6.13.7
$ n -p 8
installed : v8.17.0
$ npm --version
6.13.7
You can make this the default by setting `N_PRESERVE_NPM` to a non-empty string.
export N_PRESERVE_NPM=1
You can be explicit to get the desired behaviour whatever the environment variable:
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.
`n` downloads a prebuilt `node` package and installs to a single prefix (e.g. `/usr/local`). This overwrites the previous version. The `bin` folder in this location should be in your `PATH` (e.g. `/usr/local/bin`).
The downloads are kept in a cache folder to be used for reinstalls. The downloads are also available for limited use using `n which` and `n run` and `n exec`.
The global `npm` packages are not changed by the install, with the
exception of `npm` itself which is part of the `node` install.