dzek's mini blog

How to globally install multiple versions of an npm library

2025-12-12, in:

Often you might want to use multiple versions of globally installed library simultaneously. Some people suggest just using npx each time, but it’s slow to type and run. Some suggest nvm, but it’s a bit tedious and not good fit for all scenarios. This is how you can do it the straightforward way.

This example uses Linux paths, adjust them for Mac or Windows.

Step by step guide:

  1. (optional) you can install your “main” version as usual, ie: npm install -g eslint, so you have it available globally as eslint
  2. for each additional version create a folder somewhere, I suggest ~/.local/bin, ie: ~/.local/bin/eslint6
  3. inside initialize a npm project: pnpm init or npm init -y or yarn init -y
  4. install the library you need, ie: pnpm add eslint@^6
  5. now you can run it like this: ~/.local/bin/eslint6/node_modules/.bin/eslint --version (in the same folder you’ll find any other binaries the package provides)
  6. (optional) to make it easier to run, create a symlink somewhere in your PATH, ie: ln -s ~/.local/bin/eslint6/node_modules/.bin/eslint ~/.local/bin/eslint6
  7. (Windows users) you can create a batch file eslint6.bat somewhere in your PATH with this content:

Now you can run it like this: eslint6 --version! Great success!

Bonus

I wrote a tutorial how to use npm alias feature to have multiple versions of a library installed locally. Please note this method can’t be used for globally installed packages, because binary name does not depend directly on a package name, but what it defines in its bin field. That’s why we need a separate folder for each version.