Set up Node.js version management¶
If your project requires a specific Node.js version that is not
available from your package manager, you can use
n, Node.js version
manager. With it, you can maintain and switch between multiple versions
First uninstall Node.js, as it will conflict with the versions installed through the version manager.
Execute on the command line:
curl -L https://git.io/n-install | bash
This will run n-install to
n. The installer will notify you that it will automatically
configure environment variables. When prompted, enter
y to proceed
with the installation.
After the installation finishes, restart your terminal app to make sure that the path changes are picked up by the shell.
2 Configure (macOS only)¶
To avoid requiring
npm global installs,
configure environment variable
N_PREFIX, which will point to the
n will store Node.js binaries. With this you will also
need to update the
PATH environment variable, so that the system can
find the active binaries. Execute on the command line:
cd ~ mkdir n
You can now update environment variables. If you use
zsh shell, add
to the end of the
export N_PREFIX=~/"n" export PATH=~/"n/bin:$PATH"
Before starting with the next step, restart your terminal app to make sure that the path changes are picked up by the shell.
3 Install Node.js through
You can now use
n to install Node.js, for example latest and LTS
n latest n lts
To install exact version of Node.js, for example
10.16.0, execute on
the command line:
You can also install the latest release of the specific major version,
Note that each version on Node.js installed through
n will come with
its own version of
4 Install a package with
To install a package globally, for example
yarn, execute on the
npm install -g yarn
Packages installed globally with
npm will be installed independently
of the version of Node.js that is currently active.
5 Switch between different versions of Node.js¶
To switch between different versions of Node.js, execute on the command line:
Then select between available versions of Node.js.
Note that switching between different versions of Node.js will also
switch the accompanied version of
For more details on how to use
n, see https://github.com/tj/n.