The following steps are used to install a node.js backend server on a Linux EC2 Instance.

NOTE: with AWS EC2 Linux I prefer to do the install with root so first do a SUDO -i to get to root use mode. Then after the install is done you can copy the changes in the .profilerc from the root user to the ec2-user to make nvm and node commands available to both environments.

  1. Install the Node Version Manager (nvm) from
    curl -o- | bash
  2. To download, compile, and install the latest release of node, do this:
    nvm install node

    Then in any new shell just use the installed version:

    nvm use node
  3. Now go to Sublime text editor and create an hello.js file with:
    // hello.js
    console.log('hello world from Node.js')
  4. Upload the Hello World server node.js to a directory on the server. I created a directory called /node
  5. Now you can run your node.js Hello World test
    [ec2-user@ip-172-31-24-194 node.js]$ cd /node
    [ec2-user@ip-172-31-24-194 node.js]$ node hello.js
    hello world from Node.js
  6. Finally, you should update npm (Node Package Manager) that comes with node to the latest version. Node Package Manager works with packages available at More on the NPM in a later post.
    npm install npm@latest -g
    # FYI - use the next comand to check the current verion of npm
    npm -v

That’s All ! node.js server is setup.

You can use the which node command to find your current node.js version

[ec2-user@ip-172-31-59-183 node.js]$ which node

I also install the latest nightly build of node with the following command. You will then have the latest LTS version plus the nightly build and can switch between them with the NVM USE command.

NVM_NODEJS_ORG_MIRROR= nvm install 8

In a later post we will setup a MySQL to node database connector.