Why do I get old versions of nodejs and npm when installing with apt-get?

Debian/Ubuntu has old version in their package manager, you have to use custom PPA repository as stated here:

https://github.com/nodesource/distributions/blob/master/README.md#debinstall

Setup it with:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

Then install with Ubuntu:

sudo apt-get install --yes nodejs

To get the latest version the easiest thing to do is install nvm. nvm install instructions

  1. install nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
  2. nvm install v10.15.3
  3. (optional) set default nvm alias default v10.15.3