In this tutorial, we will install the latest versions of Node.js and npm on Ubuntu. Simply installing the packages from the default repo with apt install nodejs won't fetch the latest version, but often a couple major releases behind.

Instead, we'll take a more manual approach to installing these packages, allowing us to get much newer versions. We also get to choose between the latest beta or long term support release. Follow the steps below to get started.

Step 1. If you want, check the currently installed versions of Node.js and npm for comparison later:

$ node -v
v18.19.1

$ npm -v
9.2.0

Step 2. Start by uninstalling the current version of Node.js:

$ sudo apt -y remove nodejs

Step 3. Check what the latest version of Node.js is by going to the official download page. You will be able to see the current version as well as the latest LTS release.

Step 4. Once you've determined the version you want to install, use the command below to fetch the corresponding Node.js version's repository info.

For example, this command is for the latest version of 24.x:

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

Replace 24.x with whatever version you wish to install.

Step 5. Install Node.js with apt (this will fetch the correct version from the repo you specified in the previous step):

$ sudo apt install nodejs -y

Step 6. You're all done. Node.js and npm should be up to date:

$ node -v
v24.11.1

$ npm -v
11.6.2

Bonus: You can check the latest version of npm at this page. In case you need to manually install the latest version of npm, you can do so by running:

$ curl -qL https://www.npmjs.com/install.sh | sh