Showing posts with label EC2. Show all posts
Showing posts with label EC2. Show all posts

Wednesday, February 3, 2016

Amazon AWS - Installing Git, Node.js and npm on EC2 instance

Before we setup Node.js on AWS, you should have AWS EC2 instance setup and you should be able to login using Putty or Terminal.

Refer to my previous blog on how to setup EC2 instance -
 http://javaredhot.blogspot.com/2016/02/amazon-ec2-creating-and-setting-up.html

Now login to EC2 instance

Install Git

$ sudo yum install git
This will ask for your confirmation and then install git.


Install Node.js

To install node and npm following steps need to be performed.

To compile node we need gcc, make and git to import node source code:
sudo yum install gcc-c++ make
sudo yum install openssl-devel
sudo yum install git
Cloning node.js source code:
git clone https://github.com/nodejs/node.git
Compile and install node.js
cd node
./configure 
make
sudo make install
Add user´s directory to BIN Paths (node binaries location)
sudo su
nano /etc/ec2-user
Inside the editor scroll to where you see the line: 
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Append the value :/usr/local/bin
In some cases node does not install at /usr/local/bin and there is no soft link to the actual location. So in that case you can create a soft link from actual node location to /usr/local/bin

$ cd /usr/local/bin
$ sudo ln -s  /home/ec2-user/node/out/Release/node node
$ sudo ln -s /home/ec2-user/node/out/lib/node_modules/npm/bin/npm npm
$ sudo ln -s /home/ec2-user/node/out/lib/node_modules node_modules

Install npm

git clone https://github.com/npm/npm.git
cd npm
sudo make install

Test if node is working:

node
References:

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

Amazon EC2 - Creating and setting up an instance on AWS

Setup AWS account

Set up AWS account at - https://aws.amazon.com/


Launch EC2 instance

On AWS console, 
  • Go to AWS services dropdown and select EC2 instance
  • Create and launch EC2 instance



Select Container and configure


  • I selected Amazon Linux
  • Using the configuration available as Free Tier.

Once setup & review is complete you are now provision your instance. And it will be ready to launch



Login to the instance


You can use Mac terminal or Putty on Windows to connect AWS instance.

Store pem file downloaded when creating instance. Make sure that the permissions are restrictive. Hence use 
$ chmod 400 aws.pem

Now use ssh command to connect to instance

ssh -i /path/my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com

For more details on how to ssh, read here - http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html