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...
CodePudding user response:
One easy way is installing nvm
, which comes with the additional advantage of being able to install several different versions of node
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:
nvm install lts
or a specific version:
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
With this single command, it installs together the corresponding npm
version compatible with the node
being installed, so you don't have to worry about it. To switch between versions, just:
nvm use 14.7.0 # or 16.3.0, 12.22.1, etc
CodePudding user response:
another the most simple NodeJS version manager is the one that created by tj it's callend 'n'
you can install it as easy as :
install NPM first :
$ curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n
bash n lts
Now node and npm are available, installing n :
$ npm install -g n
then if you want to install the LTS version of NodeJS. just use this command :
$ n lts
or if you want the latest version of NodeJS
$ n latest