Easy Guide: How to Install NVM on Ubuntu for Effortless Node.js Version Control

Easy Guide: How to Install NVM on Ubuntu for Effortless Node.js Version Control

Unlock the power of Node JS version control with our comprehensive guide on installing Node Version Manager (NVM) effortlessly on your Ubuntu system. Whether you’re a DevOps, System Administrator seasoned developer or just starting with Node.js, our step-by-step instructions make the process seamless. Empower your projects with flexible Node.js version management, enhancing compatibility and productivity. Follow our user-friendly guide to master NVM installation on Ubuntu 22.04 LTS, and stay ahead in web development trends. Optimize your development environment and unleash the full potential of Node.js on your Ubuntu LTS system today.

You may install and manage various versions of Node.js on your machine with the help of Node Version Manager (NVM), a flexible utility. It makes it easier to work with different projects that require different Node.js versions by streamlining the process of switching between different versions of Node.js.

You may install NVM on an Ubuntu 22.04 Linux system with the aid of this tutorial. enables the installation of several Node versions in addition to other helpful examples.

Prerequisites:

SSh to a user account to which you need to install node.js.

You must have a running Ubuntu 22.04 Linux system with shell access.

Installing NVM on Ubuntu
It is possible to install nvm on an Ubuntu 20.04 Linux machine using a shell script. Launch a terminal on your computer, or use SSH to connect to a distant system. After installing curl on your computer using the aforementioned steps, launch the nvm installer script.

    sudo apt install curl
    curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash 

    An environment entry is created to the current user’s login script by the nvm installer script. To load the environment, you can either log out and back in again or use the command below.

    source ~/.bashrc   

    The nvm installation is successfully completed on your Ubuntu system.

    Installing Node using NVM

    You can install multiple node.js versions using nvm. And use the required version for your application from installed node.js.

    Install the latest version of node.js. Here node is the alias for the latest version.

    nvm install node 

    To install a specific version of node:

    nvm install 18.16.0 

    Replace 18.16.0 with the desired version number.

    You can also install the latest LTS (Long Term Support) version of Node.js by running:

    nvm install --lts 

    Working with NVM

    You can use the following command to list installed versions of the node for the current user.

    nvm ls 

    With this command, you can find the available node.js version for the installation.

    nvm ls-remote 

    You can also select a different version for the current session. The selected version will be the currently active version for the current shell only.

    nvm use 18.16.0 

    To find the default Node version set for the current user, type:

    nvm run default --version 

    You can run a Node script with the desired version of node.js using the below command:

    nvm exec 18.16.0 server.js