Per the Node.js website:
# Using Debian/Ubuntu
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
Then, you will have the latest version of Node.js.
If you're not a fan of curl <url> | bash -, or are using an unsupported distribution, you can try a manual installation.
Per the Node.js website:
# Using Debian/Ubuntu
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
Then, you will have the latest version of Node.js.
If you're not a fan of curl <url> | bash -, or are using an unsupported distribution, you can try a manual installation.
Node is one of the easier projects to build. Just change the version as that continues to change.
Browse to http://nodejs.org/dist/latest/ to find out the latest package version.
cd /usr/local/src
wget http://nodejs.org/dist/latest/node-v7.2.1.tar.gz
tar -xvzf node-v7.2.1.tar.gz
cd node-v7.2.1
./configure
make
sudo make install
which node
You should see /usr/local/bin/node.
node.js - how to install a latest version of Nodejs on Ubuntu? - Stack Overflow
[Ubuntu] How to install a newer version of Node than the one provided by apt?
How to Install Node.js on Ubuntu 22.04 LTS | Configure Node.js and NPM |...
What is the correct way of installing nodejs on Ubuntu?
Videos
The current LTS version can be installed via
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
In difference to the already provided answers, this evergreen link will always install the current long term supported version. So you don't need to tweak your script every couple month.
This can help:
$ sudo npm install -g n
$ sudo npm cache clean -f
$ sudo n stable
also you can replase stable with latest.
NOTE: if $ node -v shows the old version, open a new shell.