Skip to content
Changes shell's current Node.js version by updating $PATH
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Build status

Changes shell's current Node.js version by updating $PATH.

chnode is a lightweight Node.js version switcher that selects a Node.js version for a shell session. The mechanism to do this is by updating the PATH environment variable. Confining version switching to a shell session allows you to run different Node.js versions in many shell sessions simultaneously.

The lightweight design and small feature set makes chnode very fast to load, having minimal negative effect on your shell's init script.

chnode expects that Node.js versions are already installed on your system. It cannot download them for you. Instead, download Node.js binaries manually or use another tool, such as node-build, for the job.

To read more about the design rationale and a comparison to nvm and nodenv, look here.

chnode is inspired by chruby, which is awesome.


  • Selects Node.js version for a shell session by updating the PATH environment variable. Version switching is independent per shell session.
  • Small feature set by design, making the tool very fast to load.
  • Each Node.js version has its own set of global npm packages.
  • Allows accessing man pages for the selected Node.js version and its global npm packages.
  • After switching Node.js version, calls hash -r to clear the hash table for program locations.
  • Best candidate ("fuzzy") matching of Node.js versions at switching.
  • The path to the selected Node.js version is available in CHNODE_ROOT environment variable. This makes it easy to display the selected version in shell prompt.
  • Locates installed Node.js versions in ~/.nodes directory, or from a custom directory read from CHNODE_NODES_DIR shell variable.
  • Add additional Node.js versions by appending to CHNODE_NODES array shell variable.
  • Works with Bash's set -euo pipefail shell options ("strict mode").
  • Good test coverage.


GNU Bash version >= 3.2 or Zsh version >= 5.3



The manual method just downloads the latest revision of script:

curl -L '' >

It's up to you to download the script again to update.


Homebrew tap is available for macOS users:

brew tap tkareine/chnode
brew install tkareine/chnode/chnode

This is the easy way to install just the script and related documentation, and to keep the script up-to-date.

Git clone

Alternatively, clone the git repository:

git clone --depth 1

The downside of cloning is that you'll download all the non-essential project files.


Execute source command to load chnode functions:


You may append the command above into your bash init script, ~/.bashrc.

macOS does not execute ~/.bashrc automatically when opening a terminal. You might want to add the following line to ~/.bash_profile to fix it:

[[ -r ~/.bashrc ]] && source ~/.bashrc

Available Node.js versions

When shell loads chnode with source command, the script auto-detects Node.js versions installed in ~/.nodes directory.

You may override ~/.nodes directory by setting CHNODE_NODES_DIR shell variable to point to another directory. Do this before executing the source command. For example:


Sourcing populates CHNODE_NODES shell array variable with paths to subdirectories in CHNODE_NODES_DIR. CHNODE_NODES contains the Node.js versions you can select with chnode NODE_VERSION command.

After installing new Node.js versions or removing them, run chnode -R to populate CHNODE_NODES again.

For Node.js versions installed in other locations, add their paths to CHNODE_NODES after the source or chnode -R commands. For example:


Installing Node.js versions

You can use node-build to install Node.js binaries.

Installing to ~/.nodes:

node-build 10.11.0 ~/.nodes/node-10.11.0

Alternatively, download binaries from Node.js download page and extract them to ~/.nodes:

mkdir -p ~/.nodes/node-10.12.0 \
    && tar xzvf ~/Downloads/node-v10.12.0-darwin-x64.tar.gz --strip-components 1 -C ~/.nodes/node-10.12.0

Default Node.js version

Choose the default Node.js version in your shell's init script, here a 10.x series:

chnode node-10


List available Node.js versions:

$ chnode

Select a Node.js version, here a 10.x series:

$ chnode node-10

$ chnode
 * node-10.11.0

$ echo "$PATH"

$ echo "$CHNODE_ROOT"

While in the shell, install another Node.js version and reload chnode (chnode -R):

$ node-build 8.9.4 ~/.nodes/node-8.9.4

$ chnode
 * node-10.11.0

$ chnode -R  # or --reload

$ chnode
 * node-10.11.0

Reset the version (chnode -r), clearing the path that was set in the PATH environment variable:

$ chnode -r  # or --reset

$ chnode

$ echo "$PATH"

Show usage:

$ chnode -h  # or --help

Show version:

$ chnode -V  # or --version

Display current Node.js in shell prompt

You can pick up the selected Node.js version from CHNODE_ROOT environment variable. An example script to customize shell prompt is in Usage:

$ source
$ source contrib/
[tkareine@sky] [~/Projects/chnode] (node:10.11.0)



You can’t perform that action at this time.