简体   繁体   中英

Set node version for a single command using nvm

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM