Node.js is the popular language for front-end programming. A number of JavaScript frameworks are available for quick-build mobile and web application development.

Advertisement

NVM is a Node Version Manager tool. Using the NVM utility, you can install multiple node.js versions on a single system. You can also choose a specific Node version for applications.

This tutorial described how to install node.js on Ubuntu 22.10 and 21.10 systems using NVM.

Prerequisites

  • A running Ubuntu Linux system with shell access.
  • Log in with a user account to which you need to install node.js.

Step 1 – Install NVM

A shell script is available for the installation of nvm on the Ubuntu system. Use the following commands to install curl on your system, then run the nvm installer script.

Open a terminal on your system and execute:

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

The script will create the necessary environment variables in the login script of the current user. You can either log out and log in again to load the environment or use the following to load the environment.

source ~/.profile   

Step 2 – Install Node.js on Ubuntu

The NVM allows you to install and manage multiple node.js versions for each user account on a Linux system. You can easily switch to the specific version anytime.

  1. To install the latest node.js version, type:
    nvm install node 
    
  2. To install the latest LTS version of node, type:
    nvm install lts  
    
  3. To install a specific version of node, type:
    nvm install 16.4.0  
    

    You can choose any other version to install using the above command.

The very first version installed becomes the default. New shells will start with the default version of the node (e.g., nvm alias default).

Step 3 – Other Useful commands

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 16.14.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 16.14.0 server.js 

Conclusion

This tutorial described you to install node.js on Ubuntu 22.10, and 21.10 Linux systems using Node Version Manager.

Share.

1 Comment

Leave A Reply


Exit mobile version