2

Sorry Linux n00b here.

I'm trying to update nodejs in a fresh installation of Ubuntu 22.04 in a VM.

When I run this:

nodejs --version

It outputs:

v12.22.9

I've seen in many places that to update node to the latest version you execute these commands:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

When I do it it appears to work and states:

copying: node/16.16.0

However, when I nodejs --version again it still says v12.22.9

What am I doing wrong?

All I've found online tells me to do the above.

How can I update nodejs and have it say the latest version?

2 Answers 2

0
$ help type
type: type [-afptP] name [name ...]
    Display information about command type.
    
    For each NAME, indicate how it would be interpreted if used as a
    command name.
    
    Options:
      -a    display all locations containing an executable named NAME;
            includes aliases, builtins, and functions, if and only if
            the `-p' option is not also used
 ...

so $ type -a node
might print TWO instances of node, with the top one taking precedence if you do not specify which to run.

With two versions of the same, you MAY also get clashes, the default of important parts (e.g. libraries) might get mixed, depending on the actual situation. This may cause severe problems - or not.

Note: most of the time the safest option or "a good thing" to do is to remove any previous version first, then install the new / lastest...

5
  • Thanks a lot sorry for my ignorance. How can I remove the older one?
    – niico
    Commented Aug 10, 2022 at 20:23
  • I've found many links online, none get rid of all versions. still when I type which npm and which node I get 'usr/bin/npm' and 'usr/bin/nodejs'
    – niico
    Commented Aug 11, 2022 at 12:56
  • I've managed to remove node, though whatever I do when I reinstall and get version it's aways v12.22.9. How can I install the LTS?
    – niico
    Commented Aug 11, 2022 at 13:18
  • Looks like i have node and nodejs mixed up! They're different right? Or are they?
    – niico
    Commented Aug 11, 2022 at 15:18
  • 1
    I'm sorry, I'm not acquainted with node nor nodejs specifically; sudo apt purge <name-of-package> is the general way to remove something. dpkg --list | grep node might probably show more than just those; ii in the left margin is equal to "installed" (dpkg --list | head -n 10 shows all the key / legend).
    – Hannu
    Commented Aug 11, 2022 at 19:42
0

i had the same problem at the begining just open a new terminal and do node --version it upgraded to me after showing v12.22.9 for node , the new terminal showed 16.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .