How to Install Node.js on Ubuntu (2025 Updated Guide)
🚀 How to Install Node.js on Ubuntu (2025 Updated Guide)
Node.js is a powerful JavaScript runtime widely used for backend development. This guide covers the best methods to install Node.js on Ubuntu systems (including Ubuntu 16.04 and newer), so you can quickly set up your development environment or production server.
1. Install Node.js from Ubuntu Official Repositories
Ubuntu includes Node.js packages, but these may not be the latest versions. They are stable and good for quick testing or simple projects.
sudo apt update
sudo apt install nodejs npm
Note: The binary is called
nodejs
in some Ubuntu versions due to naming conflicts.
Check installed versions:
nodejs -v
npm -v
2. Install Latest Node.js Using NodeSource PPA
For newer Node.js versions, NodeSource maintains up-to-date PPAs.
Replace setup_18.x
with your preferred Node.js version (e.g., 18.x, 20.x):
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
This installs both node
and npm
. Verify installation:
node -v
npm -v
If you plan to compile native addons, install build tools:
sudo apt install build-essential
3. Install Node.js Using NVM (Node Version Manager)
NVM lets you install and manage multiple Node.js versions easily.
Install dependencies:
sudo apt update
sudo apt install build-essential libssl-dev curl
Install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
Load NVM (or restart your terminal):
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Verify NVM installed:
nvm --version
List available Node.js versions:
nvm ls-remote
Install and use a specific Node.js version (e.g., latest LTS 18):
nvm install 18
nvm use 18
nvm alias default 18
Verify:
node -v
npm -v
4. Managing Global Packages with NVM
Global packages are installed per Node.js version managed by NVM:
npm install -g yarn
To link packages locally:
npm link <package-name>
Choose the method that best fits your needs!
If you want to learn more about Node.js or managing your development environment, check the official Node.js documentation.
Happy coding! 👩💻👨💻