Reputation: 59
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.
Upvotes: 3
Views: 16041
Reputation: 49
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.
Upvotes: 1
Reputation: 20567
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.
Upvotes: 5
Reputation: 40
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
Upvotes: 2
Reputation: 11216
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.
Upvotes: 0
Reputation: 211740
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
Upvotes: 3