Install NodeJS versions
node-build is a command-line utility that makes it easy to install virtually any version of Node, from source or precompiled binary.
It is available as a plugin for nodenv that provides the
nodenv installcommand, or as a standalone program.
# Using Homebrew on macOS $ brew install node-build
As a nodenv plugin
$ mkdir -p "$(nodenv root)"/plugins $ git clone https://github.com/nodenv/node-build.git "$(nodenv root)"/plugins/node-build
As a standalone program
$ git clone https://github.com/nodenv/node-build.git $ PREFIX=/usr/local ./node-build/install.sh
# Via Homebrew $ brew update && brew upgrade node-build
As a nodenv plugin
$ git -C "$(nodenv root)"/plugins/node-build pull
To grab the latest versions from nodejs.org and generate definition files for node-build to use, check out the node-build-update-defs plugin. Once installed:
No need to wait for node-build to provide the latest definitions!
# As a nodenv plugin $ nodenv install --list # lists all available versions of Node $ nodenv install 10.13.0 # installs Node 10.13.0 to ~/.nodenv/versions
As a standalone program
$ node-build --definitions # lists all available versions of Node $ node-build 10.13.0 ~/local/node-10.13.0 # installs Node 10.13.0 to ~/local/node-10.13.0
node-build does not check for system dependencies before downloading and attempting to compile the Node source. Please ensure that all requisite libraries are available on your system.
By default, node-build will attempt to match one of the precompiled binaries to your platform. If there is a binary for your platform, it will install it instead of compiling from source. To force compilation, pass the
If you wish to develop and install a version of Node that is not yet supported by node-build, you may specify the path to a custom “build definition file” in place of a Node version number.
Use the default build definitions as a template for your custom definitions.
The build process may be configured through the following environment variables:
| Variable | Function | | ------------------------ | -------------------------------------------------------------------------------------------------- | |
TMPDIR| Where temporary files are stored. | |
NODE_BUILD_BUILD_PATH| Where sources are downloaded and built. (Default: a timestamped subdirectory of
TMPDIR) | |
NODE_BUILD_CACHE_PATH| Where to cache downloaded package files. (Default:
~/.nodenv/cacheif invoked as nodenv plugin) | |
NODE_BUILD_HTTP_CLIENT| One of
wgetto use for downloading. (Default: first one found in PATH) | |
NODE_BUILD_ARIA2_OPTS| Additional options to pass to
aria2cfor downloading. | |
NODE_BUILD_CURL_OPTS| Additional options to pass to
curlfor downloading. | |
NODE_BUILD_WGET_OPTS| Additional options to pass to
wgetfor downloading. | |
NODE_BUILD_MIRROR_CMD| A command to construct the package mirror URL. | |
NODE_BUILD_MIRROR_URL| Custom mirror URL root. | |
NODE_BUILD_SKIP_MIRROR| Bypass the download mirror and fetch all package files from their original URLs. | |
NODE_BUILD_ROOT| Custom build definition directory. (Default:
share/node-build) | |
NODE_BUILD_DEFINITIONS| Additional paths to search for build definitions. (Colon-separated list) | |
CC| Path to the C compiler. | |
CFLAGSoptions (e.g., to override
-O3). | |
./configureoptions. | |
gmake). | |
makeoptions. | |
make installoptions. | |
./configureoptions (applies only to Node source). | |
makeoptions (applies only to Node source). | |
make installoptions (applies only to Node source). |
-p) flag to apply a patch to the Node (/iojs/chakracore) source code before building. Patches are read from
# applying a single patch $ nodenv install --patch 11.1.0 < /path/to/node.patch
applying a patch from HTTP
$ nodenv install --patch 11.1.0 <
If you have theshasum,openssl, orsha256sumtool installed, node-build will automatically verify the SHA2 checksum of each downloaded package before installing it.
Checksums are optional and specified as anchors on the package URL in each definition. All definitions bundled with node-build include checksums.
By default, node-build downloads package files from the official URL specified in the definition file.# example: install_package "node-v12.0.0" "https://nodejs.org/dist/v12.0.0/node-v12.0.0.tar.gz#"
node-build will attempt to construct a mirror url by invokingNODE_BUILD_MIRROR_CMDwith two arguments:package_urlandchecksum. The provided command should print the desired mirror's complete package URL. IfNODE_BUILD_MIRROR_CMDis unset, package mirror URL construction defaults to replacinghttps://nodejs.org/distwithNODE_BUILD_MIRROR_URL.
node-build will first try to fetch this package from$NODE_BUILD_MIRROR_URL/(note: this is the complete URL), where is the checksum for the file.
It will fall back to downloading the package from the original location if: - the package was not found on the mirror; - the mirror is down; - the download is corrupt, i.e. the file's checksum doesn't match; - no tool is available to calculate the checksum; or -NODE_BUILD_SKIP_MIRRORis enabled.
You may specify a custom mirror by settingNODE_BUILD_MIRROR_URL.
Keeping the build directory after installation
Bothnode-buildandnodenv installaccept the-kor--keepflag, which tells node-build to keep the downloaded source after installation. This can be useful if you need to usegdbandmemprofwith Node.
Source code will be kept in a parallel directory tree$(nodenv root)/sourceswhen using--keepwith thenodenv installcommand. You should specify the location of the source code with theNODE_BUILD_BUILD_PATHenvironment variable when using--keepwithnode-build.
Retry installation without v/node-/node-v prefix
The nodenv-install plugin can attempt a retry if the installation failed due to a missing definition file. If the given node version name begins with 'v', 'node', or 'node-v', the retry will drop the prefix and try again. For instance, ifnodenv install node-v11.0.0fails because a definition file does not exist by the name "node-v11.0.0", it will retry as "11.0.0". For this retry to be attempted, the environment variableNODENV_PREFIX_RETRYmust be non-empty.
If you can't find an answer on the wiki, open an issue on the issue tracker. Be sure to include the full build log for build failures.