3

Answer: Follow the steps in this link

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

I am running ubuntu on an ec2 instance and need to sudo npm install something. I am given the error that sudo npm is not recognized.

There is a previous thread that is 7 years old. On EC2: sudo node command not found, but node without sudo is ok I tried every solution there and nothing worked.

I think the problem is using NVM to install npm and node. How can I install these so that they are compatible with sudo? Thanks!

Hanley Soilsmith
  • 579
  • 2
  • 9
  • 27
  • Why are you using sudo to do this? Also is `apt install npm` not working? If you already have nvm installed what does it say when you try to install the latest stable npm version? – Shardj Dec 06 '18 at 17:17
  • Installing the latest web3 module requires sudo npm install. I've terminated the instance that I was trying everything on to have a clean start; looking at the answer below I'm going to switch to RedHat. However, I did confirm that the latest npm was installed. – Hanley Soilsmith Dec 07 '18 at 01:45

3 Answers3

2

You can run the following command

sudo yum install nodejs npm --enablerepo=epel

For more, you can also install using the following link also: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html

Second Approach:

Install NPM

git clone https://github.com/isaacs/npm.git
cd npm
sudo env PATH=$HOME/local/node/bin:$PATH make install

Now you can install npm packages and run javascript node files as usual!

sudo npm install forever -g
sudo npm install express -g

Resource Link: http://www.wisdomofjim.com/blog/how-to-install-node-and-npm-on-an-ec2-server

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • 1
    First approach returns `Error getting repository data for epel, repository not found` Second approach fails at sudo env PATH... with error message `make: *** No rule to make target `install'. Stop.` Thanks though, I will research these error messages – Hanley Soilsmith Dec 07 '18 at 02:23
  • As I said above, the first and second approaches did not work. Installation through the resource link http://www.wisdomofjim.com/blog/how-to-install-node-and-npm-on-an-ec2-server did work. Thank you very much :) – Hanley Soilsmith Dec 07 '18 at 03:41
1

I dont know if my problem is the same as yours (i think is similar), but i tried to run "sudo npm install" on a amazon linux ec2 machine and it gave me the "sudo: npm: command not found" type of problem.

I followed the instructions recommended by AWS to install node and NPM (https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html).

I solve this by changing the owner and group of the directory and files (package.json and package-lock.json): chown ec2-user:ec2-user nameDir

and then i run npm install again. It worked!

Luiza Rodrigues
  • 185
  • 1
  • 2
  • 15
0

You can use NVM. You can follow this link which gives proper steps to install node on ec2 instance.

The90sArtist
  • 177
  • 1
  • 1
  • 9
  • Using NVM (at least the way I was doing it) does not easily allow for `sudo npm` module installation. If someone needs this functionality, I would recommend the ec2 redhat instance and following the installation instructions in the link. – Hanley Soilsmith Dec 07 '18 at 04:42