Installing server packages for Ubuntu 18.04 VPS

2021.09.06

Ubuntu

Updating the local package index. 

$ sudo apt update

Error: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)

The problem is that some apt processes are running, so using the "killall" command:

$ sudo killall apt-get

Or to remove the locking file.

$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/cache/apt/archives/lock
$ sudo rm /var/lib/dpkg/lock

Error: apt-get update "the following signatures couldn’t be verified because the public key is not available"

Solve: Upgrading the entire system and importing your missing keys.

$ sudo apt-get upgrade
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <YOUR_MISSING_KEY>

Nginx

Installing nginx by command:

$ sudo apt install nginx

Afterwards, you must adjusting the firewall.

Firstly, list the application that ufw knowns by typing

$ sudo ufw app list

As you can see, there are three available options for enable:

Available applications:
 Nginx Full
 Nginx HTTP
 Nginx HTTPS
 OpenSSH

Because, we haven't configured SSL for the server yet, you will only need to allow HTTP traffic in port 80. By the way, you also need to allow OpenSSH traffic for remote control.

$ sudo ufw allow 'Nginx HTTP'
$ sudo ufw allow 'OpenSSH'

Enabling ufw firewall and displaying the result:

$ sudo ufw enable 
$ sudo ufw status

NodeJS

Version: 14.x

Following these commands:

$ curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
$ sudo apt-get install -y nodejs

You may also need development tools to build native addons:

sudo apt-get install gcc g++ make

To install the Yarn package manager, run:

$ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
$ echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn

To check nodejs version, type:

$ node -v

Process Manager

In this case, we are using pm2.

$ npm install pm2 -g

SSH Key

From client to server

(Updating)

From server to Github

Typing:

$ ssh-keygen -t ed25519 -C "your_email@example.com"

You just enter for skipping.

Adding SSH key to the ssh-agent:

$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_ed25519 # Replacing id_ed25519 by your filename

Cat and copy your public key

$ cat ~/.ssh/id_ed25519.pub

Afterwards, it must be added to the Github account.


By: Vũ Anh Hào