Update for 2024
Since this question was posted, version 20 became the newest LTS version. So Ahmed Boutaraa's answer was correct for the version 14 part of the question, but people stumbling on this question may be seeking the most recent LTS. If you follow those instructions, you will be stuck in version 14.
Luckily, NodeSource also provides an installation script that installs the current LTS rather than a specific version. That should make this answer a bit more future-proof. You can also get the same info straight from the source.
As an aside, there is a script called nvm
that is great for managing your node version. It makes it easy to install multiple versions, like if you work with multiple projects with different version requirements or if you want to experiment with the latest version and easily switch back to LTS for regular work. You can find installation instructions on their repository.
How to install the latest LTS version
This set of instructions will install whatever version is the latest LTS version. When a new version is released, you may have to run these instructions again to pull the new install script for the new version.
# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
# OR as root
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
How to install the latest non-LTS version
This set of instructions will install whatever version is the latest non-LTS version. When a new version is released, you may have to run these instructions again to pull the new install script for the new version.
# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
# OR as root
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs
How to lock into v21 (latest, for now)
# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash -
sudo apt-get install -y nodejs
# OR as root
curl -fsSL https://deb.nodesource.com/setup_21.x | bash -
apt-get install -y nodejs
How to lock into v20 (current LST)
# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# OR as root
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
sudo snap refresh node --channel=11/stable