×
Community Blog Install Node.js on Alibaba Cloud

Install Node.js on Alibaba Cloud

In this tutorial, you will be installing and setting up Node.js on an Alibaba Cloud ECS instance.

By Arslan Ud Din Shafiq, Alibaba Cloud Community Blog author and Alibaba Cloud MVP.

Node.js is an open-source cross-platform environment for JavaScript that allows you to run JS code outside the browser. Node.js also allows you to run scripts on server side for producing dynamic webpages. Rather than using different server side and client-side languages, by using Node.js alone, you can unify your web application around a single programming language - adding a whole lot of convenience to your workload.

In this tutorial, you will be installing and setting up Node.js on an Alibaba Cloud Elastic Compute Service (ECS) instance with Ubuntu 16.04.

Prerequisites

  • You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get $300 – $1200 worth in Alibaba Cloud credits for your new account. If you don't know how to setup your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.
  • A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  • Domain name must be pointed to your Alibaba Cloud ECS's IP address
  • Access to VNC console in your Alibaba Cloud or SSH client installed in your PC
  • Set up your server's hostname and create user with root privileges.

Setting up Your Environment

Setting up Your Server

Before proceeding with installation of any kind of package, run the following command to update your Ubuntu system. To run this command, remember to login from non-root user with sudo privileges.

# sudo apt update && sudo apt upgrade

Installing software-properties-common

Software-properties-common package is required to get the supported files for installation of Docker CE. In order to install software-properties-common package, follow the steps below.

To install software-properties-common, run the following command.

# sudo apt-get install software-properties-common -y 

Installing apt-transport-https

Apt-transport-https is required for installation of Docker CE. In order to install apt-transport-https, complete the steps below.

To install apt-transport-https, run the command below.

# sudo apt-get install apt-transport-https -y 

Installing ca-certificates

Ca-certificates is required for installation of Docker CE. In order to install ca-certificates, follow the steps below.

To install ca-certificates, run the command.

# sudo apt-get install ca-certificates -y 

Installing Curl

Curl is required for installation of Docker CE. In order to install curl, follow the steps below.

To install curl, run the command.

# sudo apt-get install curl -y 

Installing Docker CE

To install Docker community edition, complete the steps below:

Add GPG key for Docker by running the command below.

# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Run the following command to verify the fingerprint of GPG key.

# sudo apt-key fingerprint 0EBFCD88

Now add the Docker repository by running the command below.

# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Update your system by running the command below to load added repository.

# sudo apt update

Run the following command to install Docker.

# sudo apt install docker-ce

Add your username to docker group by running the command below.

# sudo adduser aareez docker 

Close your current shell session and start a new session because, otherwise, you won't be able to run docker and you may see permission errors.

Next, run the following command to check either docker run correctly or not.

# docker run hello-world

Installing Docker Compose

To download and install Docker compose, follow the steps below.

Run the following command to download and install latest version of docker compose.

# sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Set the permissions for file by running the command below.

# sudo chmod +x /usr/local/bin/docker-compose

Get list of started containers by running the following command.

# docker container ls --all

1

Stop container using port 8080. To do so, get container id, replace it with 8baab990c424 below and run the command below.

# docker stop 8baab990c424

Installing and Setting up Node.js

In this tutorial specifically, I will use official image of Node.js for installation on Docker. To download and install Node.js, you will need to run the following command which will pull latest Nodejs from official docker repository.

# docker pull linode/server-node-js

Now run the following command to run docker image.

# docker run -d -p 80:3000 linode/server-node-js

Now you can verify it by accessing your Alibaba Cloud ECS IP address or domain name pointing to that IP address. http://your_domain.tld/test.htm

You will see the following page.

2

Setting up Firewalls and Ports

If you have activated firewalls, you will have to define a rule in Alibaba Cloud security group for your cloud server to add exception for port 80/tcp and 443/tcp. You can enable these ports while creating ECS instance, but in case if you forgot to unblock these ports, you can follow the procedure in this guide: Add security group rules

1 0 0
Share on

Alibaba Clouder

2,605 posts | 747 followers

You may also like

Comments

5428418315590345 April 13, 2021 at 3:12 pm

This install Docker and Docket NodeJS image. It's not standalone NodeJS. It's not just NodeJS itself.