NPM installation issues on Amazon EC2 instance

Hey everyone, I’m having trouble setting up NPM on my Amazon EC2 instance. Node.js is working fine, but when I try to install NPM, it’s not going smoothly.

I’ve been using this command:

sudo curl http://npmjs.org/install.sh | sh

The install seems to get stuck. It says it’s fetching the NPM package, but then nothing happens. It just sits there doing nothing.

Has anyone else run into this problem? Any ideas on how to fix it or a different way to install NPM on EC2? I’m kind of stuck here and could really use some help. Thanks!

hey isaac, i had similar issues. try using nvm (node version manager) instead. it’s way easier. just run:

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

then install node+npm with:

nvm install node

works like a charm for me on ec2!

I’ve faced this exact issue on EC2 before. The curl method can be finicky sometimes. Here’s what worked for me:

First, install Node.js from the EPEL repository:

sudo yum install -y epel-release
sudo yum install -y nodejs

Then, install npm separately:

sudo yum install -y npm

If that doesn’t work, try clearing your yum cache:

sudo yum clean all
sudo yum update

And then attempt the npm installation again. This approach solved it for me when I was setting up a new EC2 instance last month. It’s a bit more manual, but it gives you more control over the process and helps pinpoint where things might be going wrong.

I encountered a similar issue on EC2 recently. The problem might be related to outdated package repositories. First, update your system:

sudo yum update -y

Then, install Node.js and NPM using the NodeSource repository:

curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
sudo yum install -y nodejs

This method installs both Node.js and NPM together, which should resolve your issue. Remember to check your firewall settings if you’re still having connection problems. Also, ensure you’re using a supported EC2 instance type for the Node.js version you’re trying to install.