I recently started working on two projects that require different NodeJS versions, hence I found an elegant solution – NVM (a.k.a node version manager), a tool that helps you effectively manage your node versions for each project.
NVM allows you to install multiple versions of Node and switch between them depending on the project that you’re working on.
Installing NVM on Windows
- NVM does not support windows, but no worries, there is a similar tool, called nvm-windows. Access the following link
- Click on “Download Now!” button
3. Click and install the latest release .exe file
3. Open the downloaded .exe file and complete the installation wizzard.
Note: Open up a CLI (cmd, powershell, git bash, etc) and run ‘nvm -v‘. If it was installed correctly, the nvm version should be displayed.
Installing NVM on Linux/MacOS
Open up a terminal and run one of the following commands
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Note: Running either of these commands will download and install nvm on your device under ~/.nvm directory and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc)
export NVM_DIR=“$([ -z “${XDG_CONFIG_HOME-}“ ] && printf %s “${HOME}/.nvm“ || printf %s “${XDG_CONFIG_HOME}/nvm“)“ [ -s “$NVM_DIR/nvm.sh“ ] && \. “$NVM_DIR/nvm.sh“ # This loads nvm
How to use NVM? - Cheatsheet
With NVM you can install, uninstall or switch between different NodeJS versions on your device,
depending on your needs.
- nvm install latest
installs the latest NodeJS version
- nvm install stable installs the latest stable NodeJS version
- nvm ls lists locally installed versions of node
- nvm install YOUR_VERSION (e.g. nvm install 18.19.0) installs specific NodeJS version
- nvm use YOUR_VERSION (e.g. nvm use 18.19.0) switch and use specific NodeJS version
- nvm alias default 18.16.1 sets default version of NodeJS
Enjoyed this article? Make sure to subscribe to my YouTube Channel for more Test Automation tutorials, and follow me on LinkedIn and Twitter for regular insights.
Looking to improve your test automation skills?
I’ve created a personalized 1-on-1 Mentoring program refined to boost YOUR skills. Reach out at iamrv@razvanvancea.ro for more details and together will create a learning path adapted to your current skills and goals that you are aiming for, in a timely-efficient manner🚀