DEV Community

rosa-rzi
rosa-rzi

Posted on

How to manage node versions across projects

If you're currently utilizing Docker container projects, there's no need to worry about your existing Node version. But that’s another different topic from this one that I’ll probably share with you in the future. For now, I'd like to share my story with using nvm across all my Node.js projects on my macOS system.

Note: If you have a pre-existing Node.js version on your machine, it will remain accessible as the default version. This allows you to continue using and installing nvm.

1) Get nvm installed in your macOS terminal console

Option 1:

brew install nvm

Option 2:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash

Option 3:

wget -q0- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash

2) Indicated nodejs version required in my project folder in a git-tracked .nvmrc file:

echo v18.14.1 > .nvmrc

install it

npm install v18.14.1

3) This does not take effect automatically on cd, the user must do it:

nvm use

Now you can see all the node versions you have installed with

nvm list

.nvmrc is documented at: https://github.com/creationix/nvm/tree/02997b0753f66c9790c6016ed022ed2072c22603#nvmrc

Top comments (0)