How to install node.js in its latest version (12.x) by Ubuntu terminal?

I'm trying to install nodeJS on my Linux.However, even putting the codes for Version 12.x:

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

The terminal only installs version 8.10. When I run the command sudo apt-get install -y nodejs build-essential, it runs the processes and in the end it works:

nodejs is already the newest version (8.10.0~dfsg-2ubuntu0.4).
0 pacotes atualizados, 0 pacotes novos instalados, 0 a serem removidos e 22 não atualizados.

Could anyone explain the problem to me?

Author: riki481, 2019-09-17

2 answers

I install using Node version Manager, not least because the apt-get it does not always have the most current and instable version.

First in the terminal install the package using curl or wget, just run one of the commands:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

Make sure your installation is correct:

command -v nvm

Note: it is important to do this after closing and opening a new terminal.

List the versions of node:

nvm ls-remote

Install the version you want:

nvm install 10.16.3

I put version 10.16.3 because it is the most instable version according to nodejs documentation

 1
Author: Marconi, 2019-09-17 11:03:42

Guy tries this command:

sudo apt install nodejs

Second option:

sudo apt install snapd
sudo snap install node --channel=12/stable --classic

Conforms link

 1
Author: Gustavo Castro, 2019-09-17 02:43:42