'Error installing node js on Amazon EC2

I am trying to install Node Js and npm on my new Amazon EC2 instance but I can't succeed in doing so.

I am referring to the official doc : https://nodejs.org/en/download/package-manager/

I run

sudo curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -

But I am getting an error :

error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)

I have seen similar case problems that were solved by using sudo but even using sudo I can't get it.

Thanks for your help !



Solution 1:[1]

Adding a sudo right before bash did it for me

curl --silent --location https://rpm.nodesource.com/setup_5.x |sudo bash -

Then

sudo yum install -y nodejs

Solution 2:[2]

Use this command and you'll be good to go:

curl -sL https://rpm.nodesource.com/setup_17.x | bash -

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 thomas.g
Solution 2 Eric Aya