If you try to use apt-package manager to install the latest version of node, there’s a chance that you’ll download the latest version in the Ubuntu app storee and not the lastest release version of NodeJS.
This is mainly because the Ubuntu team may take a while to test new versions of the software and release them to the official Ubuntu store.
To install the latest version in the Ubuntu app store but may not be the latest release version,
$ sudo apt install nodejs -y
To install the lastest release version of NodeJS, do a quick google search for “latest stable release version of nodejs”. Note which version is the current one.
Let’s install nvm first. This will allow us to use different versions of node.
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Restart your terminal and verify. You should have version 0.35.5 installed or higher.
$ nvm --version
Install the NodeJS version that you recorded earlier. Note that if you need other versions, you can also install them using the same command.
$ nvm install <version>
Verify the latest version installed.
$ node -v
If you have multiple node versions in your machine, you can switch between them.
$ nvm use <version-number>
We can also use Nodesource to install the NodeJS package.
$ curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Note: v18 is the current “release” NodeJS version and will be promoted to Long-term Support (LTS) in October 2022.
NPM should also be automatically installed. You can verify the NPM version by running the command below.
$ npm -v
If it is not installed, proceed to the next steps.
sudo apt install -y
We may need to run the command below for certain npm packages to run.
$ sudo apt install -y build-essential
You can read more about the installation process in this freeCodeCamp article.
</details>