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.
- Execute the following command in the terminal to update the package manager:
sudo apt update
- Install Node.js.
sudo apt install nodejs
- Install the Node.js package manager npm.
sudo apt install npm
Manually install Node.js:
- 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.
- 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)
- Move the uncompressed folder to the /usr/local directory.
sudo mv node-vx.x.x-linux-x64 /usr/local/
- 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.