Master Node.js with NVM: Simplified Management and Installation

Efficiency in software development depends largely on how we manage the tools we use daily. One of the common challenges for JavaScript developers is managing different versions of Node.js for various projects. That's where Node Version Manager (NVM) comes in, an indispensable tool for modern developers. In this article we are going to explore how to install and use NVM to manage multiple versions of Node.js in your development environment.

What is Node Version Manager (NVM)?

NVM is a solution that allows you to install and switch between various versions of Node.js easily and efficiently without affecting the operating system as a whole. It is ideal for situations where you need to test and run projects with different versions of Node.js or when different projects require specific versions.

NVM installation

Installing NVM is relatively simple and usually varies slightly depending on your operating system. Here I will offer you a step by step for UNIX-based systems, which includes macOS and most Linux distributions.

On UNIX-based systems (Linux/Mac)

Step 1: Download the installation script

Open a terminal and type the following command to download and run the NVM installation script:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | Bash

This command uses curl to download the script and then run it by passing it to the shell using Bash.

Step 2: Configure your terminal

After installation, you need to make sure your terminal can find the command nvm. Generally, the terminal loads it automatically through your profile file, such as .bash_profile, .zshrc, .profile, either .bashrc.

For that, you can simply close and reopen your terminal or run the following command to load NVM:

source ~/.nvm/nvm.sh

Step 3: Verify the installation

Once NVM is installed, you can check if it was installed correctly using:

nvm --version

Using NVM to handle Node.js versions

With NVM installed, you are ready to install and manage different versions of Node.js.

Installing Node.js versions

To install a new version of Node.js, use the command nvm install followed by the version number. Example:

nvm install 14.17.0

Switching between Node.js versions

Switching from one version to another is as simple as running:

nvm use 14.17.0

List of available versions

You can list all the versions of Node.js you have installed with:

nvm ls

And to see the versions available for installation:

nvm ls-remote

Set a default version

To avoid having to select a version every time you open the terminal, you can set a default version of Node.js with:

nvm alias default 14.17.0

Delete a version of Node.js

If you need to get rid of an installed version, you can simply do the following:

nvm uninstall 14.17.0

Advanced Tips with NVM

Use of .nvmrc

For projects that require a specific version of Node.js, you can create a file .nvmrc in the root of the project with the desired version written to it. By navigating to the project directory, you can run nvm use to automatically switch to the specified version.

Automation with scripts

You can automate version switching by including scripts in your package.json let them execute nvm use before running other commands, ensuring that you are always on the necessary version.

Good Practices and Common Discussions

LTS versions: It is recommended to use versions of Node.js that are officially long-term maintained (LTS) to avoid security and compatibility issues.

Versions in production: Make sure the version of Node.js you select for production is extensively tested and remains stable under your application's specific workload.

Resources and Support

For any questions or more personalized support regarding the installation and management of NVM or problems related to Node.js, you can contact us through NelkoDev Contact. Furthermore, I invite you to visit NelkoDev for more resources and articles related to modern software development.

Managing multiple versions of Node.js no longer has to be a headache. With NVM, you will gain not only efficiency, but also the ability to ensure that your projects run exactly as they should in the environment in which you developed them. Make the most of this tool and optimize your workflow as a developer!

Facebook
Twitter
Email
Print

Leave a Reply

Your email address will not be published. Required fields are marked *

en_GBEnglish