I’m having trouble setting up NPM on my Amazon EC2 server. Node.js is working fine, but I can’t seem to get NPM installed properly. I tried using this command:
sudo curl http://npmjs.org/install.sh | sh
The installation process starts but then gets stuck. It shows ‘fetching: http://registry.npmjs.org/npm/-/npm-1.0.106.tgz’ and doesn’t progress from there. I’ve left it running for a while, but nothing changes.
Does anyone know what might be causing this? Is there a different way to install NPM on EC2? Or maybe there’s a step I’m missing? Any help would be appreciated!
I have experienced similar issues with NPM on EC2 instances. The problem may be due to network restrictions or using an outdated installation method. Instead of running the curl command from npmjs.org, a better approach is to use Node Version Manager (NVM).
First, install NVM with the command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
After installing, source your bash configuration with:
source ~/.bashrc
Then install Node.js, which automatically includes NPM, using:
nvm install node
This method typically avoids common installation issues. Also, checking your EC2 security group settings for proper outbound connectivity may help resolve any remaining problems.
I’ve dealt with this exact issue on EC2 before. The curl method can be finicky. What worked for me was using the Node Version Manager (NVM) approach, but with a slight twist.
First, I made sure my system was up to date:
sudo yum update -y
Then I installed development tools:
sudo yum groupinstall ‘Development Tools’ -y
After that, I used NVM to install Node and NPM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
This method solved my NPM issues and gave me more control over Node versions. If you’re still having trouble, check your EC2 instance’s outbound traffic rules. Sometimes overly restrictive settings can cause installation hiccups.
hey claire, i had similar probs. try this instead:
sudo yum install nodejs npm --enablerepo=epel
it worked 4 me on ec2. if that fails, check ur instance’s network settings. sometimes they block stuff. good luck!