I found out that Ubuntu 18.04 already has nodejs 8_10 in its apt repository.
root@ip-172-31-18-129:/home/ubuntu# apt-cache policy nodejs
nodejs:
Installed: 6.14.1-1nodesource1
Candidate: 8.10.0~dfsg-2ubuntu0.3
Version table:
8.10.0~dfsg-2ubuntu0.3 500
500 http://eu-west-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages
8.10.0~dfsg-2ubuntu0.2 500
500 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages
8.10.0~dfsg-2 500
500 http://eu-west-1.ec2.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
*** 6.14.1-1nodesource1 500
500 https://deb.nodesource.com/node_6.x bionic/main amd64 Packages
100 /var/lib/dpkg/status
I installed the specific version I wanted by:
apt-get install nodejs=6.14.1-1nodesource1