DEV Community

Cover image for How to Install NodeJs on Linux
crit3cal
crit3cal

Posted on • Updated on

How to Install NodeJs on Linux

Node.js is an open-source, cross-platform JavaScript runtime environment used for executing JavaScript code outside of a web browser.It's lightweight, and beginner friendly and used by many big companies like Netflix and Uber

There are different ways to install Node.js on a Linux-based system. However, in this tutorial, we will focus on two comonly used methods: using the official package manager and using the Node.js version manager (nvm).


Method 1: Using the Official Package Manager

The easiest way to install Node.js on a Linux system is by using the official package manager of your distribution.

  1. Ubuntu/Debian

    Open the terminal and update the package index:

    sudo apt-get update
    
  2. Install NodeJS

    sudo apt-get install nodejs
    
  3. Verify the installation

    To check if Node.js is installed correctly, run the following command:

    node -v
    

    This should output the version number of Node.js installed on your system.

  4. Install npm:

    npm is a package manager for Node.js. To install it, run the following command:

    sudo apt-get install npm
    
  5. Verify the installation

    To check if npm is installed correctly, run the following command:

    npm -v
    

    This should output the version number of npm installed on your system.

  6. Update npm:

    It is always recommended to update npm to its latest version. Run the following command to update npm:

    sudo npm install -g npm
    

Method 2: Using the Official Package Manager

The Node Version Manager (nvm) is a tool that allows you to easily switch between different versions of Node.js on your system.

  1. Install nvm

    Open the terminal and run the following command:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    

    This will download and install nvm on your system.

    Troubleshooting on Linux

    On Linux, after running the install script, if you get nvm: command not found or see no feedback from your terminal after you type command -v nvm, simply close your current terminal, open a new terminal, and try verifying again.
    Alternatively, you can run the following commands for the different shells on the command line:

    bash: source ~/.bashrc

    zsh: source ~/.zshrc

    ksh: . ~/.profile

    These should pick up the nvm command.

  2. Verify the installation

    To check if nvm is installed correctly, run the following command:

    nvm --version
    

    This should output the version number of nvm installed on your system.

  3. Install Node.js:

    Once you have nvm installed, you can use it to install any version of Node.js that you want. For example, to install the latest stable version of Node.js, run the following command:

    nvm install --lts
    
  4. Verify the installation

    To check if Node.js is installed correctly, run the following command:

    node -v
    

    This should output the version number of Node.js installed on your system.

Conclusion

In this tutorial, we have shown you two ways to install Node.js on a Linux system: using the official package manager and using the Node Version Manager (nvm). Choose the method that best suits your needs and get started with building amazing web applications with Node.js!

Top comments (3)

Collapse
 
jhonnyfreire profile image
Jhonny Freire • Edited

Another alternative (my favorite) is asdf

Collapse
 
hackreveal profile image
Prakash Tiwari

Is it written by AI

Image description

Collapse
 
rex_10 profile image
crit3cal

using quillbot to improve the sentences