Node Version Manager (NVM) is an command-line utility for installing and managing Node.js versions. This tool is helpful for developer to quickly install specific Node.js version. It also allows users to install, manage, and work with multiple Node.js versions on the same system without conflict. All the Node.js developers which is upgrading to the latest Ubuntu 24.04 can use this tools to setup the development environment. This also helpful for setting up production servers that required multiple versions as same time.
This tutorial will help to install NVM on Ubuntu 24.04 and demonstrate how to use it to manage your Node.js versions.
Step 1: Installing NVM on Ubuntu
To install NVM on your Ubuntu system, follow these steps:
- Open the Terminal: You can do this by searching for ‘Terminal’ in your application menu or by pressing Ctrl + Alt + T.
- Execute NVM Installation Script: Run the following command in the 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
Make sure to check the NVM GitHub page for the latest version number and update the URL accordingly.
- Activate NVM: Once the installation script completes, you need to either 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 instance, to switch 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 any new shell sessions.
Additional Commands
- Install the latest LTS version of Node.js:
nvm install --lts
- Uninstall a specific Node.js version:
nvm uninstall <version_number>
Conclusion
NVM is a powerful tool that simplifies the management of multiple Node.js versions on a single machine. It is especially useful for developers who need to ensure compatibility across different projects or are testing their applications across multiple Node.js versions. 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 versions effectively.