Wednesday, April 22, 2015

AWS EC2: Install Node.js on an Amazon Linux AMI instance

I wanted to install Node.js on my Amazon Linux EC2 instance. Unlike Ubuntu, I can't just apt-get install nodejs.

Update: 2017-10-28

1. Install node version manager (nvm):
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

2. Activate nvm:
. ~/.nvm/nvm.sh

3. Install the desired version of nodejs:
nvm install 6.11.5
node -v 


** Alternatives **

To install version 4.x:
curl --silent --location https://rpm.nodesource.com/setup_4.x | sudo bash -
sudo yum -y install nodejs
node -v


To install version 6.x:
curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
sudo yum -y install nodejs
node -v


To update npm:
sudo npm install -g npm
npm -v


To uninstall nodejs 0.10.x:
sudo yum erase nodejs
sudo rm -f /usr/local/bin/node



** Outdated **
The solution appears to be very simple. I just need to enable the EPEL (Extra Packages for Enterprise Linux) repository to get yum install to work.

To install npm 2.15.11 and nodejs 0.10.x:
1. Edit the repository config file
  sudo nano /etc/yum.repos.d/epel.repo

2. In the [epel] section, change the enabled flag to 1

3. Press Ctrl+O to save the file, and then Ctrl+X to exit

4. Update yum
  sudo yum update

5. Install npm and Node.js
  sudo yum install npm

6. Verify Node.js is installed
  node -v


Ref:
Tutorial: Setting Up Node.js on an Amazon EC2 Instance - AWS SDK for JavaScript
How to yum install Node.JS on Amazon Linux - Stack Overflow
How to install node.js on AWS AMI Linux instance | SpiderSoft

No comments: