How to Install Node.js on Ubuntu 24.04: A Step‑by‑Step Guide
Node.js has become the backbone of countless web applications, real‑time services, and command‑line tools. If you’re running Ubuntu 24.04 and want to harness the power of JavaScript on the server, learning how to install Node.js on Ubuntu 24.04 is essential. In this guide, we’ll walk through two reliable methods—using Ubuntu’s default repositories and leveraging the NodeSource binary distributions—to get you up and running in minutes. For detailed commands and context, you can also follow the official Vultr tutorial
Why Use Node.js on Ubuntu 24.04?
Ubuntu 24.04 “Noble Numbat” is a long‑term support (LTS) release, providing five years of security updates and stability. Pairing it with Node.js allows you to:
Run JavaScript end‑to‑end, from frontend to backend
Build high‑performance, event‑driven applications
Leverage NPM’s vast ecosystem of packages and libraries
Deploy microservices and real‑time APIs with ease
Whether you’re developing chat apps, RESTful APIs, or streaming services, Ubuntu 24.04 and Node.js offer a rock‑solid platform.
Prerequisites
Before you begin, ensure you have:
A machine or VM running Ubuntu 24.04
A user with sudo privileges
Terminal or SSH access
An internet connection
Method 1: Ubuntu’s Default APT Repository
Ubuntu’s built‑in repositories include Node.js, though it may not always be the very latest version. This approach is fast and straightforward.
Update your package index sudo apt update
Install Node.js sudo apt install -y nodejs
Install NPM (the Node Package Manager) sudo apt install -y npm
Verify the installation node -v
npm -v
You should see the installed versions printed in your terminal. If the version of Node.js meets your needs, you’re all set!
Method 2: NodeSource Binary Distributions (Recommended)
For the latest Long‑Term Support (LTS) release of Node.js, use the NodeSource repository. This ensures you get security patches and new features as they’re released.
Install the NodeSource setup script for the current LTS: curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
Install Node.js (this also pulls in NPM): sudo apt install -y nodejs
Confirm your versions: node -v
npm -v
Using NodeSource gives you a more up‑to‑date Node.js environment, ideal for production and development alike.
Optional: Install Build Tools
Some NPM packages contain native extensions that must be compiled. To install the necessary build tools:
sudo apt install -y build-essential
This installs gcc, make, and related tools, enabling you to install packages like bcrypt or node-gyp without errors.
Troubleshooting Tips
Permission errors: If global NPM installs fail with EACCES, consider using npx for one‑off tools or configure an NPM directory in your HOME.
PATH issues: Ensure /usr/bin/node and /usr/bin/npm are in your $PATH.
Firewall rules: If your Node.js service listens on a custom port (e.g., 3000), open it with sudo ufw allow 3000.
Service management: To run Node.js apps as a systemd service, create a unit file under /etc/systemd/system/ and manage it with sudo systemctl enable|start <your‑service>.
Uninstalling Node.js and NPM
Should you ever need to remove Node.js and NPM:
sudo apt remove --purge -y nodejs npm
sudo apt autoremove -y
This cleans out both the runtime and package manager, along with unused dependencies.
Conclusion
Mastering how to install Node.js on Ubuntu 24.04 gives you access to a vibrant ecosystem and empowers you to build scalable, high‑performance applications. Whether you opt for the simplicity of Ubuntu’s repositories or the cutting‑edge capabilities of NodeSource, you’ll benefit from the stability of Ubuntu 24.04 LTS and the flexibility of Node.js.
For a full, illustrated walkthrough and advanced configuration options, check out the official guide at Vultr. Happy coding!