Skip to content
Edwin Shin edited this page Apr 17, 2019 · 24 revisions

Installing a Node.js version to a directory

locate the desired Node.js version
curl -s | awk '/^v[0-9]/{ print $1 }' | less
create version directory
mkdir -p $NODE_VERSIONS/node-v8.9.4
download for Mac OS X or Linux

Mac OS X

curl -fsSL | tar xvz --strip 1 -C $NODE_VERSIONS/node-v8.9.4


curl -fsSL | tar xvz --strip 1 -C $NODE_VERSIONS/node-v8.9.4
export path
export PATH="$NODE_VERSIONS/node-v8.9.4/bin:$PATH"

Load Node.js version from a .node-version or .nvmrc file.

Loads a Node.js version from directory prefix specified by $NODE_VERSIONS environment variable. You can further customize the sub-directory lookup via $NODE_VERSION_PREFIX.

If you specify a partial Node.js version (i.e. "8.9" or "8"), a fuzzy match is performed and the highest matching version installed is selected.


set -e
use node

.node-version or .nvmrc


Load Node.js version specified in .envrc


use node 8.9.4

Using the layout node directive

You can optionally add the layout node directive in your .envrc to have the node_modules/bin path added to the PATH (though, this is generally not recommended).

Using nvm

It's possible to use nvm to manage Node versions and direnv to load them. For this add the following in the ~/.config/direnv/direnvrc or ~/.direnvrc file:

use_nvm() {
  local node_version=$1

  if [[ -e $nvm_sh ]]; then
    source $nvm_sh
    nvm use $node_version

Using nvm, install a couple of versions, e.g. nvm install 10.15.3.

Then in any project's .envrc include:

use nvm 10.15.3


related projects is a set of direnvrc helper functions to handle various nodejs-related scenarios

You can’t perform that action at this time.