Installing Node.js on Linux (Ubuntu/CentOS): A Comprehensive Guide
Learn how to install Node.js and npm on popular Linux distributions like Ubuntu and CentOS. This tutorial provides detailed, step-by-step instructions, covering various installation methods and troubleshooting common issues for a smooth and successful Node.js setup on your Linux system.
Installing Node.js on Linux (Ubuntu/CentOS)
This guide explains how to install Node.js on various Linux distributions, including Ubuntu and CentOS. The steps might vary slightly depending on your specific distribution.
Installing Node.js on Ubuntu
Here's how to install Node.js and npm (Node Package Manager) on Ubuntu:
- Open the Terminal: Use the keyboard shortcut (Ctrl+Alt+T).
- Install `python-software-properties` (if not already installed):
- Add the Node.js PPA (Personal Package Archive):
- Update the package list:
- Install Node.js and npm:
- Verify the Installation: Check the versions of Node.js and npm:
- View Installed Packages: (Optional) Use this command to see all installed packages, including Node.js:
Install python-software-properties
sudo apt-get install python-software-properties
Add Node.js PPA
sudo apt-add-repository ppa:chris-lea/node.js
Press Enter after each command. You may be prompted to press Enter again to continue.
Update Package List
sudo apt-get update
(This might take a few moments.)
Install Node.js and npm
sudo apt-get install nodejs npm
(Some distributions might require a separate `sudo apt-get install nodejs` command.)
Verify Installation
node --version
npm -v
View Installed Packages
dpkg --get-selections
You'll need administrator privileges (using `sudo`) for these commands. CentOS and other distributions will have slightly different package managers (e.g., `yum` instead of `apt-get`), but the general principles remain the same; consult your distribution's documentation for specific instructions.
next →
← prev