How To Install Node.js and NPM On CentOS Stream 10

What is Node.js?
Node.js is an open-source, cross-platform runtime environment that allows developers to run JavaScript code outside of a web browser. Built on Chrome’s V8 JavaScript engine, Node.js is widely used for building scalable, high-performance applications, including web servers, APIs, microservices, and real-time applications.
Key Features of Node.js
- Asynchronous and Event-Driven: Node.js operates on a non-blocking I/O model, making it highly efficient for handling multiple requests simultaneously.
- Fast Execution: Powered by the V8 engine, Node.js executes JavaScript code at lightning speed.
- Single-Threaded with Event Loop: Unlike traditional multi-threaded models, Node.js uses a single-threaded approach with an event loop, improving performance.
- Cross-Platform: Runs on Windows, macOS, Linux, and various cloud environments.
- Rich Ecosystem: Supported by a vast library of open-source packages via NPM.
What is NPM?
NPM (Node Package Manager) is the default package manager for Node.js. It allows developers to install, manage, and share JavaScript packages with ease. NPM comes pre-installed with Node.js and provides access to thousands of libraries, making development faster and more efficient.
Features of NPM
- Dependency Management: Automatically handles package dependencies.
- Package Registry: Provides access to a vast collection of open-source libraries.
- Version Control: Allows developers to manage different versions of packages.
- Script Automation: Enables running scripts for testing, building, and deployment.
Installing Node.js and NPM on CentOS Stream 10
This guide will show multiple methods to install Node.js and NPM on CentOS. There are three options to install Node.js and NPM :
- Install Node.js Using NVM (Node Version Manager)
- Install Node.js and NPM Using CentOS Default Repositories
- Install Node.js and NPM Using NodeSource Repository
The Node.js and NPM installation details will be explained briefly on the next sub chapters.
Method 1: Install Node.js Using NVM (Node Version Manager)
1. Install NVM:
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
2. Reload shell configuration:
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"
3. Verify NVM installation: nvm --version
4. Install Node.js (latest LTS version):
nvm install –lts
5. Set the default Node.js version: nvm use 23.8.0


Method 2: Install Node.js and NPM Using CentOS Default Repositories
1. Update the system:
sudo dnf update -y
2. Install Node.js:
sudo dnf install -y nodejs
3. Verify the installation:
node -v
npm -v

Method 3: Install Node.js and NPM Using NodeSource Repository
1. Add NodeSource repository (for latest stable version):
curl -fsSL https://rpm.nodesource.com/setup_23.x | sudo bash -
2. Install Node.js and NPM:
sudo dnf install -y nodejs
3. Verify the installation:
node -v
npm -v

Conclusion
Node.js and NPM are essential tools for modern web development. Whether you are building a simple website, a RESTful API, or a full-fledged web application, Node.js provides the performance and scalability needed. Meanwhile, NPM enhances productivity by offering a robust package management system. Mastering these tools will significantly boost your development workflow!