Loading...
NVM and Nodejs on Mac - Top
Author Cloudapp
E.G.

Nodejs + NVM (Node Version Manager) - The great team

March 1, 2024
Table of Contents

The Node Version Manager (NVM) is an open-source version manager for Node.js (Node). NVM is easy to understand and works on any POSIX-compliant shell (e.g. sh or bash). NVM allows you to easily install and manage different versions of Node and switch between them on a per-shell basis. This guide describes how to install NVM, and how to use it to install and run different versions of Node.

What is Nodejs

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that executes JavaScript code outside a web browser. More Details can be found on our overview page.

Advantages of NVM

Because Node changes quickly, testing applications with different versions is often difficult. Next.js 14 for instance requires Node 18.17.0 etc. Since NVM enables quick and effortless switching between Node versions, it is much easier to test version compatibility and upgrades with multiple libraries. NVM also simplifies the installation and compilation process. If you're using Windows I recommend this Windows-specific version of nvm.

Download and install nvm


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

or use wget if you like it more

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

This script clones the nvm repository into ~/.nvm. Then it updates your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) to source the nvm.sh it contains

With the command

cd && tail zshrc

you should see this

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

Restart your terminal (On Mac ZSH)

source ~/.zshrc 

Let's check if the installation was successful

nvm --version
# 0.38.0

Show all remotely available versions of node

nvm ls-remote

List Node Versions with NVM

Review all installed versions of Node with the ls command:

nvm ls

Daily commands

//Install node 18.17.0
nvm install v18.17.0

//Install node 18.16.0
nvm install v18.16.0

//Change default node version
nvm alias default 18.16.0

//Switch to node version which is set as default
nvm use default

//Select Node Version
nvm use 18.17.0

Use NVM to Install the Latest LTS Node.js Release

Any Node.js version can be in one of the following three release phases: Current, Long Term Support (LTS), and Maintenance. The LTS release includes new features, bug fixes, and updates that have been approved.

Use the following command to install the latest LTS version of Node.js on your system
nvm install --lts

Last but not least - NVM Uninstall Steps

If you no longer intend to use NVM, uninstall it with the unload command.

First, deactivate NVM with the nvm deactivate command to clear any path variables
nvm deactivate
Next, use the unload command to uninstall NVM
nvm unload

Here you can find all NVM-related posts

Here you can find additional information regarding NVM on nodejs.org