n: Minimal Node Version Switcher for CI
n <version> downloads a Node version and installs it into N_PREFIX (default /usr/local), replacing the active node binary directly with no shims.
n is the simplest Node manager: it just swaps the binaries under a prefix. Because it writes to the prefix instead of using shims or sourced functions, the common CI snag is filesystem permissions, not sourcing.
What it does
n downloads a Node version into $N_PREFIX/n/versions and symlinks/copies it into $N_PREFIX/bin, so node directly points at the chosen version. There is no shim layer and no shell function to source; the active node is whatever n last installed into the prefix.
Common usage
# install n itself, then a Node version
export N_PREFIX="$HOME/.n"; export PATH="$N_PREFIX/bin:$PATH"
n 20.11.1 # install + activate that version
n lts # latest LTS
n exec 18 node -v # run a one-off under another version
node -vOptions
| Command / setting | What it does |
|---|---|
| n <version> | Install and activate a Node version |
| n lts / n latest | Install the LTS or newest release |
| n exec <v> <cmd> | Run a command under a specific version |
| n rm <v> | Remove an installed version |
| N_PREFIX | Install prefix (use a writable dir in CI) |
| n --download | Only download, do not activate |
In CI
Set N_PREFIX to a user-writable directory (e.g. $HOME/.n) and put $N_PREFIX/bin first on PATH so you avoid sudo and PATH ordering surprises. Cache $N_PREFIX/n/versions. Because n replaces the binary in place, the switch persists across steps as long as PATH points at the prefix.
Common errors in CI
"mkdir: cannot create directory ... Permission denied" or "Error: sudo required" means n is writing to a root-owned prefix like /usr/local; set N_PREFIX to a writable path. "version not found" means an invalid version string; use n ls-remote. If node -v is unchanged after n, the active node on PATH is from a different location than $N_PREFIX/bin.