How to Install npm on CentOS 7 When EPEL Repository Fails: Node.js Package Management Solutions


2 views

When working with CentOS 7, many developers encounter the frustrating situation where Node.js installs successfully but npm remains unavailable. This typically occurs because:

  • The base EPEL repository doesn't include npm in its package list
  • Node.js and npm have diverged in their packaging approach
  • CentOS 7's default repositories are often outdated for modern JavaScript development

Here are three proven approaches to get npm working:

Method 1: Enable NodeSource Repository

The most reliable approach is to use NodeSource's curated repositories:

# Install NodeSource setup script
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -

# Install both Node.js and npm
sudo yum install -y nodejs

This will give you both Node.js and npm in properly synced versions. For other versions, simply replace 14.x in the URL with your desired version (e.g., 16.x).

Method 2: Using NVM (Node Version Manager)

For development environments, NVM provides the most flexibility:

# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

# Reload shell
source ~/.bashrc

# Install Node.js (which includes npm)
nvm install --lts

Method 3: Manual Installation from Source

If you need absolute control:

# Install dependencies
sudo yum install -y gcc-c++ make

# Download and extract Node.js
curl -sL https://nodejs.org/dist/v14.18.1/node-v14.18.1.tar.gz | tar -xz

# Compile and install
cd node-v14.18.1
./configure
make -j$(nproc)
sudo make install

After installation, always verify both components:

node -v
npm -v

If npm still isn't available, check your PATH variable:

echo $PATH
which npm

If you encounter permission problems:

# Fix npm permissions
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules

For SSL certificate issues:

# Update certificates
sudo yum update ca-certificates

On older CentOS 7 systems, consider these optimizations:

# Increase file watcher limits
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

When working with CentOS 7, many developers encounter a frustrating scenario where yum install npm fails despite having EPEL repository configured. The error typically states "No package npm available". This happens because:

  • EPEL repositories don't always include the latest npm package
  • Node.js and npm packages have different distribution channels
  • CentOS 7's default repos are often outdated for modern JS development

Method 1: Using NodeSource Repository

The most reliable approach is to use NodeSource's maintained repositories:

# Install NodeSource setup script
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -

# Install Node.js (which includes npm)
sudo yum install -y nodejs

# Verify installation
node -v
npm -v

Method 2: Manual Installation via NVM

For development environments, NVM provides better version management:

# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

# Load NVM
source ~/.bashrc

# Install specific Node version
nvm install 14

# Set default version
nvm alias default 14

If you're constrained to yum, try enabling additional repositories:

# Enable EPEL and additional repos
sudo yum install -y epel-release
sudo yum install -y --enablerepo=epel-testing nodejs npm

If you still encounter problems, try these diagnostics:

# Check available versions
yum --showduplicates list nodejs

# Clean yum cache
sudo yum clean all
sudo yum makecache

# Alternative search
yum search npm | grep -i npm

Remember that the npm package might be named differently in some repositories, like nodejs-npm.