When working with Node.js development environments, flexibility is key. The Node Version Manager (NVM) is a powerful tool that lets developers easily install and manage multiple versions of Node.js on a single system. However, there are times when you might need to install a custom version of NVM or Node.js  in your virtual machine— for example, a forked version for testing, a version with patched features, or an older revision not available in the main NVM registry.

In this article, we’ll walk through the steps to install a custom version of NVM and then use it to install a custom or local version of Node.js.

Why Install a Custom Version?

There are several use cases for installing a custom version:

  • Testing patches or forks of NVM or Node.js.

  • Using Node.js builds with experimental features.

  • Working offline with locally compiled versions.

  • Compatibility with legacy projects requiring specific environments.

Step 1: Installing a Custom Version of NVM

Option 1: Clone a Forked Repository

If you’re working with a fork or custom branch of NVM:

git clone https://github.com/your-username/nvm.git ~/.nvm
cd ~/.nvm
git checkout your-custom-branch

Then, add NVM to your shell configuration:

echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bashrc
source ~/.bashrc

If you’re using zsh, replace .bashrc with .zshrc.

✅ Tip: Test the installation by running nvm –version.

Step 2: Installing a Custom Version of Node.js

Option 1: Install Node.js from Source

If you have a custom version of Node.js built from source:

  1. Clone the Node.js repository or your custom fork:

git clone https://github.com/nodejs/node.git
cd node
git checkout your-custom-branch
  1. Compile and install it locally:

./configure
make -j4
make install DESTDIR=$HOME/custom-node
  1. Use NVM to “install” this version:

nvm install v18.99.99 --lts --no-download

Then, manually symlink your local build:

nvm use v18.99.99
# or
nvm alias custom-node v18.99.99

Option 2: Install from a Custom Tarball

If you have a precompiled Node.js tarball:

nvm install v18.99.99 --lts --no-download
cp -r node-v18.99.99-linux-x64 ~/.nvm/versions/node/v18.99.99

Then use it as normal:

nvm use v18.99.99

Troubleshooting

  • nvm not found: Ensure the path to NVM is correctly added in your shell configuration.

  • Permission issues: Use sudo cautiously. NVM and Node.js are designed to run without elevated privileges.

  • Compilation errors: Ensure all build dependencies are installed (build-essential, python, etc.).

Conclusion

Installing a custom version of NVM or Node.js gives you fine-grained control over your development environment. Whether you’re testing experimental features or working on a legacy system, these custom setups are invaluable. By following the steps above, you can create a robust and tailored Node.js development workflow suited to your needs.