Node.js Setup on Linux: Complete Guide

There are generally two ways to install Node.js on Linux: using a package manager or manually installing it. Below are the steps for each of these methods:

Install Node.js using a package manager.

  1. Execute the following command in the terminal to update the package manager:
sudo apt update
  1. Install Node.js.
sudo apt install nodejs
  1. Install the Node.js package manager npm.
sudo apt install npm

Manually install Node.js:

  1. Open the Node.js official website in your browser (https://nodejs.org/) to download the Node.js installation package that is compatible with your system.
  2. Enter the download directory in the terminal and execute the following command to unzip the installation package:
tar -xvf node-vx.x.x-linux-x64.tar.xz

(Note: x.x.x is the version number of Node.js, please refer to the downloaded file name to determine)

  1. Move the uncompressed folder to the /usr/local directory.
sudo mv node-vx.x.x-linux-x64 /usr/local/
  1. Create a symbolic link.
sudo ln -s /usr/local/node-vx.x.x-linux-x64/bin/node /usr/bin/node
sudo ln -s /usr/local/node-vx.x.x-linux-x64/bin/npm /usr/bin/npm

After installation is complete, you can use the following command in the terminal to check if Node.js and npm were installed successfully:

node -v
npm -v

After installation is complete, you can start using Node.js to write and run JavaScript programs.

bannerAds