I am new to js and wanted to install nodejs LTS version and npm on ubuntu 21.10. So, I followed the nodesources repository install instructions and it had stated to use the install script for LTS and it worked fine as I followed the same instructions mentioned in it.
But, after installation of the nodejs package, when I try to check the node -v: it shows as 12.x.x, while the latest LTS version for nodejs is 16.x.x. I did not understand why this is happening and what is the solution for this?
P.S: I have mentioned the commands that I had used for installation of nodejs LTS 16.x.x, and the site link is this: https://github.com/nodesource/distributions/blob/master/README.md
cmd:
Node.js LTS (v16.x):
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
Please note: I have not installed the optional build tools yet and not the npm as well. I’m confused on what to do now…
2
Answers
One easy way is installing
nvm
, which comes with the additional advantage of being able to install several different versions ofnode
and switching between them easily:https://github.com/nvm-sh/nvm#installing-and-updating
Once installed, in some occasions you have to close the terminal and reopen it for the
nvm
command to work. From then on, simply install the version you need:or a specific version:
With this single command, it installs together the corresponding
npm
version compatible with thenode
being installed, so you don’t have to worry about it. To switch between versions, just:another the most simple NodeJS version manager is the one that created by tj
it’s callend ‘n’
https://github.com/tj/n
N in action
you can install it as easy as :
install NPM first :
Now node and npm are available, installing n :
then if you want to install the LTS version of NodeJS. just use this command :
or if you want the latest version of NodeJS