Installing NPM on AWS EC2

node.jsAmazon Ec2Amazon Web-ServicesNpm

node.js Problem Overview


Working on Ec2 on AWS.

I have installed Node.js and it works fine.

But the problem arises when trying to install npm.

I am using the following command to install it:

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

But the install seems to freeze... I get "fetching: http://registry.npmjs.org/npm/-/npm-1.0.106.tgz" at the prompt and it stays on like this.

Have any idea what is going on here?

node.js Solutions


Solution 1 - node.js

sudo yum install nodejs npm --enablerepo=epel

Solution 2 - node.js

To install NodeJS 6.x execute the following commands:

curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
yum install nodejs --enablerepo=nodesource

Update

You can install NodeJS 7 and 8 in the same way. Just specify the version you need instead of 6 in the command above.

Update

To update to NodeJS 16 (or any other version) do the following:

rm -rf /etc/yum.repos.d/nodesource-el*
curl -sL https://rpm.nodesource.com/setup_16.x | sudo -E bash -
yum install nodejs --enablerepo=nodesource

Solution 3 - node.js

Follow this AWS Tutorial that uses Node Version Manager.

Node Version Manager (NVM) lets you install multiple versions of Node.js and switch between them.


Here are the steps:

Install NVM

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

Activate NVM

. ~/.nvm/nvm.sh

Install Node (choose version)

nvm install 4.4.5

Confirm Successful Installation

node -e "console.log('Running Node.js ' + process.version)"

Solution 4 - node.js

Simplest way to install npm/nodejs on Amazon Linux 2 ec2 isntance:

  1. First install epel repo using amazon-linux-extras command as below:

> sudo amazon-linux-extras install epel

  1. Now install npm and nodejs as below:

> sudo yum install nodejs npm

  1. you can verify the version of node and npm as below:

> node -v > > npm -v

PS. I've tested this on Amazon Linux 2 AMI (HVM) ec2 instance.

Solution 5 - node.js

Firstly

sudo yum install make

You can run this to get zip of desired version of node

wget https://nodejs.org/dist/v8.10.0/node-v8.10.0.tar.gz

Then you can unzip it like this

tar -xvf node-v8.10.0.tar.gz

then go in to the extracted directory and install node like this

./configure && make && sudo make install

Solution 6 - node.js

This guide worked perfectly: https://tecadmin.net/install-latest-nodejs-amazon-linux/

  1. Make sure you have make

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

  1. Install source

# curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -

  1. Install node

# sudo yum install -y nodejs

Note - you'll have to run sudo npm install to get the installs to work.

Solution 7 - node.js

I found his tutorial that has been very usefull to me: The last chapter explains how to install node and npm compiling it.

http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/#installNode

Solution 8 - node.js

Get the http://npmjs.org/install.sh file on your system first and then execute it directly instead of piping with curl.

  • Use chmod +x install.sh to make it executable
  • Then run ./install.sh

Solution 9 - node.js

I did it manually. Why mess with installers that break or don't put things where I want them? Such were the problems encountered while installing *node.js" on Amazon Web Services, that a manual install was the easy way to get the result I wanted.

I want a GLOBAL install of node and npm on AWS. By that I mean install should be put in a place like /usr/bin, so that all users have access. Surprisingly, AWS apparently doesn't give support to that idea. AWS encourages using nvm, node version manager, but that seems to always install in a user directory, and not a system level directory. After being frustrated when the "rpm" solutions (mentioned elsewhere) failed, I finally decided to just do the installation manually.

In a browser, go to nodejs.org download page:

https://nodejs.org/en/download/

Find a link that says:

All download options

Click through that; it goes to an index page with a URL like:

https://nodejs.org/dist/v14.16.1/

There I looked for the name that had "linux" and "x86" in the name. I wrote this down, or select-and-copied, to get the correct spelling. In my case it was:

node-v14.16.1-linux-x64.tar.gz

Putting the two parts together, I got the following URL:

https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.gz

So that's what is to be downloaded using curl.

I have a "temp" directory conveniently located in my home dir.

cd ~/temp

The download was accomplished with "curl". Note that the -o option was used to give the output file the name of my choosing. Of course, I chose to give it the same name as the web site file.

curl -o node-v14.16.1-linux-x64.tar.gz  https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.gz

Untar the downloaded file.

tar xf node-v14.16.1-linux-x64.tar.gz

Conveniently, it creates its own directory. Go there.

cd node-v14.16.1-linux-x64 || exit 1;

Observe that the delivery consists of a relatively small number of files and directories (since node_modules is dealt with as a unit).

In my case, I had an old and bad implementation still installed, so the following commands were used to move aside any junk that might happen to be in the way. Some commands errored out because the old junk didn't exist. That's ok, error while moving to -OLD just means there is nothing to move; which is good.

Note: I put all these mv (move) commands into a script file, made it executable, and ran it as sudo. The alternative is to run each line individually as sudo.

mv /usr/bin/node    /usr/bin/node-OLD
mv /usr/bin/npm             /usr/bin/npm-OLD
mv /usr/bin/npx             /usr/bin/npx-OLD
mv /usr/include/node                /usr/include/node-OLD
mv /usr/lib/node_modules    /usr/lib/node_modules-OLD
mv /usr/share/doc/node                      /usr/share/doc/node-OLD
mv /usr/share/man/man1/node.1               /usr/share/man/man1/node.1-OLD
mv /usr/share/systemtap/tapset/node.stp             /usr/share/systemtap/tapset/node.stp-OLD

An here is the actual install. Remember, this is occurring in the untarred directory, in my case node-v14.16.1-linux-x64.

mv bin/node         /usr/bin
mv bin/npm          /usr/bin
mv bin/npx          /usr/bin
mv include/node             /usr/include
mv lib/node_modules         /usr/lib
mv share/doc/node           /usr/share/doc
mv share/man/man1/node.1            /usr/share/man/man1
mv share/systemtap/tapset/node.stp          /usr/share/systemtap/tapset/

That's it, all finished.

Solution 10 - node.js

This works for me:

sudo apt install npm

Solution 11 - node.js

Edit as my answer wasn't pertinent anymore:

Try:

curl --silent --location https://rpm.nodesource.com/setup | bash -

yum -y install nodejs 

https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#enterprise-linux-and-fedora-core

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondadeView Question on Stackoverflow
Solution 1 - node.jsTedView Answer on Stackoverflow
Solution 2 - node.jsIhor BurlachenkoView Answer on Stackoverflow
Solution 3 - node.jsDerek SoikeView Answer on Stackoverflow
Solution 4 - node.jsmohlatif227View Answer on Stackoverflow
Solution 5 - node.jsKhurram W. MalikView Answer on Stackoverflow
Solution 6 - node.jsJared WilberView Answer on Stackoverflow
Solution 7 - node.jsjbaylinaView Answer on Stackoverflow
Solution 8 - node.jswswoodruffView Answer on Stackoverflow
Solution 9 - node.jsIAM_AL_XView Answer on Stackoverflow
Solution 10 - node.jsZafer ATLIView Answer on Stackoverflow
Solution 11 - node.jsfkoesslerView Answer on Stackoverflow