Introduction
Node Version Manager (NVM) is an essential tool for any developer working with Node.js. It allows you to easily install, manage and work with multiple versions of Node.js on the same system without conflicts. This guide will walk you through the process of installing NVM on Ubuntu 24.04 and show you how to use it to manage your Node.js releases.
Step 1: Installing NVM
To install NVM on your Ubuntu system, follow these steps:
Open Terminal: You can do this by searching for "Terminal" in the application menu or by pressing Ctrl+Alt+T.
Run the NVM installation script: Run the following command in terminal to download the NVM installation script from the project's GitHub repository. Using Curl:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Using Wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Be sure to check the NVM GitHub page for the latest version number and update the URL accordingly.
Enable NVM: Once the installation script is complete, you need to close and reopen the terminal or run the following command to use nvm immediately.
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"
Step 2: Installing Node.js using NVM
After installing NVM, you can install Node.js. NVM makes it easy to install any version of Node.js. To install the latest version, use:
nvm install node
To install a specific version of Node.js, you can do so by specifying the version number, for example:
nvm install 20.12.0
Step 3: Using NVM to manage Node.js versions
You can list all installed Node.js versions using:
nvm ls
To switch between installed Node.js versions, use:
nvm use <version_number>
For example, to upgrade to Node.js version 18.20.0, you would use:
nvm use 18.20.0
Step 4: Setting a Default Node.js Version
To avoid having to manually switch versions every time you open a new terminal, you can set a default Node.js version with NVM:
nvm alias default <version_number>
This command makes the specified version the default for each new shell session.
Additional commands
- Install the latest LTS version of Node.js:
nvm install --lts
- Uninstall a specific version of Node.js:
nvm uninstall <version_number>
Conclusion
NVM is a powerful tool that makes it easy to manage multiple versions of Node.js on a single machine. It is especially useful for developers who need to ensure compatibility between different projects or who are testing their applications on multiple versions of Node.js. By following the steps outlined in this guide, you should now have NVM installed on your Ubuntu 24.04 system and know how to use it to manage your Node.js releases effectively.