Home > Net >  Set node version for a single command using nvm
Set node version for a single command using nvm

Time:01-25

I have a command that must be run with Node 16 installed, no other version. However, I need to have the latest version of Node installed for regular use.

How can I configure things, perhaps with environment variables, so that just that one command uses Node 16?

Something like nvm use 16 && node -v && nvm use 19 is too slow, but aliasing in .zshrc is an option.

CodePudding user response:

What I've done in one of my Projects is this:

I've switched to node 16: nvm use 16. After that which node showed this path: /root/.nvm/versions/node/v16.19.0/bin/node

So I've simply created a symlink for this executable: ln -s $(which node) /usr/bin/node16

Finally I switched back the version: nvm use system

Now you can use your default node Version with node and the desired node-version for this command with node16.

  • Related