Home > Software design >  how to install a latest version of Nodejs on Ubuntu?
how to install a latest version of Nodejs on Ubuntu?

Time:12-22

I start using ubuntu (22.04.1) recently. I want to install nodejs latest version (currently v18.12.1 LTS). But my node --version showing version v12.22.9.

First I install node using sudo apt-get install nodejs. Then I re-install my node but before re-install I update my system using sudo apt update && sudo apt upgrade. But i keep getting same result. node version v12.22.9.

CodePudding user response:

Don't use the distribution's default, Ubuntu is extremely conservative with bumping versions of things like Node, so instead go with Node's repository.

The current location is documented in the installer instructions:

curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

Where the setup_ scripts usually do a good job of getting everything properly sorted.

For the 18 LTS version:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

CodePudding user response:

I would use nvm - Node Version Manager, see https://github.com/nvm-sh/nvm#install--update-script

This has a couple of advantages: you don't change the system's node version (which might be used elsewhere) and you may select a distinct (older or newer) version of node accompanied by appropriate installations of npm, yarn, a.s.o. It's simple to install "global" packages just locally (kind of oxymoron...) for your user. You don't need root permission for these.

CodePudding user response:

1-Install CURL if you don't have:

sudo apt-get install curl

2-Run the following command to add the PPA to the Ubuntu system:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&\

3-After successfully adding the PPA to the system, execute the command below to install Node on Ubuntu:

sudo apt-get install nodejs

4-check the version number of the installed software for node :

node -v

  • Related