How to Install Multiple Versions of Node JS

Node.js is a powerful JavaScript runtime environment that allows developers to build scalable server-side applications. Built on Chrome’s V8 engine, it is widely used for creating web applications, APIs, and real-time chat services. Its non-blocking, event-driven architecture ensures high performance, making it a popular choice for developers worldwide.

As Node.js continues to evolve, different projects may require different Node.js versions. For instance, an older project might depend on a previous Node.js version, while newer projects might need the latest features. Additionally, compatibility with various libraries or frameworks often dictates which version is necessary.

Install multiple version Node js ensures smooth workflow across projects without conflicts. This guide will explain how to set up multiple Node.js versions on your system using tools like Node Version Manager (NVM) or similar methods. By managing versions efficiently, developers can maintain flexibility and productivity in diverse development environments.

Installing Multiple Versions of Node JS

The easiest and most effective way to achieve this is by using Node Version Manager (NVM), a command-line tool designed specifically for managing Node.js versions. Below is a step-by-step guide to installing and using NVM to handle multiple Node.js versions.

Step 1: Update System Packages

Before installing any new software, it’s essential to ensure your system packages are up to date. This minimizes compatibility issues and ensures you have the latest security patches. Run the following command:

sudo apt update && sudo apt upgrade -y
sudo apt update

Step 2: Download and Install NVM

Next, use the curl command to download the NVM installation script:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
git hub user

This command sets up NVM on your system, making it possible to manage multiple Node.js versions.

Step 3: Activate NVM

Once NVM is installed, its configuration is added to your shell profile file (e.g., ~/.bashrc). To apply these changes without restarting your terminal, run:

source ~/.bashrc
bash rc

Alternatively, restart your terminal for changes to take effect.

Step 4: Verify NVM Installation

To confirm that NVM is installed correctly, check its version:

nvm --version
nvm version

If the command returns a version number (e.g., 0.40.1), NVM has been successfully installed.

Step 5: Installing Multiple Node JS Versions

Now let’s display all available Node.js versions that NVM supports with:

nvm list-remote
latest version

This command displays a list of stable, unstable, and Long-Term Support (LTS) versions.

In the output, you can see that the latest available LTS version is v22.11.0 so you can install it either by providing the version name or by executing the below command:

nvm install --lts
nvm install lts

LTS versions are recommended for most projects because they are stable and supported for extended periods.

To display the installed Node JS versions, you can execute:

nvm list
nvm list

Initially, only the LTS version will appear if it is the first version you installed.

If a specific project requires a newer or older Node.js version, you can install it by specifying the version number:

nvm install 23.0.0
nvm install 23

After executing the nvm list command again, you will now see both the LTS version and the newly installed version listed:

nvm list

Step 6: Switch Between Node.js Versions

Some projects may depend on specific Node.js versions due to differences in feature support or dependencies. By using NVM, you can easily switch between versions to maintain compatibility without reinstalling Node.js manually.

To do that you can execute:

nvm use 23.0.0
nvm use 23

Features of Node.js

Node.js stands out for its unique features, making it an excellent choice for building scalable and high-performance applications. Below are its key features explained in detail:

1. Event-Driven Architecture

Node.js uses an event-driven, non-blocking architecture that handles multiple client requests efficiently. Instead of waiting for one task to complete, it processes tasks asynchronously, ensuring optimal use of resources. This feature is ideal for building real-time applications like chat servers and online games.

Single-Threaded with Non-Blocking I/O

Node.js operates on a single-threaded model while supporting non-blocking input/output operations. This allows it to handle numerous concurrent requests without creating multiple threads, reducing memory consumption and improving performance.

3. Fast Execution

Powered by Google’s V8 engine, Node.js translates JavaScript into machine code for faster execution. This speed is crucial for applications requiring quick responses, such as data-intensive APIs and streaming platforms.

4. NPM (Node Package Manager)

Node.js comes with NPM, which offers a vast library of reusable packages and modules. Developers can quickly integrate these packages to reduce development time and enhance functionality. 

5. Cross-Platform Compatibility

Node.js runs seamlessly across multiple platforms, including Windows, Linux, and macOS. This flexibility makes it suitable for diverse environments, simplifying deployment and development. 

6. Scalability

Node.js supports horizontal and vertical scaling, allowing developers to scale applications efficiently. It is widely used for building applications that grow with user demand, such as e-commerce websites and social networks.  

These features make Node.js a popular and versatile choice for modern web development.

Conclusion

Node.js is a powerful runtime environment that enables developers to build efficient, scalable, and high-performance applications. Its features, such as an event-driven architecture, single-threaded model, and non-blocking I/O, make it ideal for diverse use cases, including real-time applications and APIs. The availability of NPM and cross-platform compatibility further enhances its appeal for developers across different environments.

Managing multiple Node.js versions is crucial for maintaining compatibility across projects, especially when working with varying dependencies or legacy systems. By using Node Version Manager (NVM) on Linux, you can seamlessly install, switch between, and manage multiple Node.js versions. Following the step-by-step guide—from updating system packages and installing NVM command node js to listing and switching versions—ensures a streamlined workflow, boosting productivity and flexibility in development projects.

Unlock the power of dedicated resources with Ultahost’s high-speed Virtual Private Servers, which are fully customizable to meet your specific needs. With Ultahost, you can effortlessly manage your VPS to fit your requirements as your demands increase.

FAQ

What is Node.js?
Why would I need multiple versions of Node.js?
What is NVM, and why is it useful?
How do I install NVM on Linux?
How do I check which Node.js versions are installed?
How do I install the latest LTS version of Node.js?
Can I uninstall a Node.js version I no longer need?

Related Post

How to Install TypeScript in Node JS

TypeScript is a strong, statically typed superset of Ja...

How to Install GraphQL in Node JS

GraphQL is a tool for APIs that lets clients request on...

How to Install Node-RED on Windows

Node-RED is a powerful flow based programming tool that...

How to Install Node.js and NPM on Windows

Node.js enables the execution of JavaScript code outsid...

Leave a Comment