10

I'm unable to update nodejs, and I can't see why.

If I were to make a guess, I'd say that I have two repositories listed in apt-get, that both contain a nodejs package.

Here's what I've done:

Remove old version:

sudo apt-get remove --purge nodejs npm

Then, going by https://github.com/nodesource/distributions#installation-instructions, I've run:

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -

And then:

sudo apt-get install -y nodejs

I then run:

nodejs -v

Which returns:

v0.10.25

Can anyone explain what's going wrong? And how I can remedy this situation?

Many thanks.

4
  • You'll want to figure out where your current version of Node is coming from. which nodejs will tell you that. Then, run apt-get remove... again and see what the output of which nodejs is after attempting to remove it. Dec 25, 2015 at 14:34
  • which nodejs isn't found. It uninstalls it completely when I use remove.
    – Jack_Hu
    Dec 30, 2015 at 13:43
  • In case anyone else finds this question here. I had the same problem. I decided to install NVM to use it for different versions. The instructions said to close the terminal and open a new one after installing NVM. I did and decided to randomly check the current node version. It had changed to the newly installed one. I'm not sure if installing NVM did anything, I'd think not, so anyone with the same problem might want to try to close the terminal and open a new one and then run node --version.
    – hubbabubba
    Oct 17, 2019 at 13:37
  • It is the npm that comes with node via apt. It is worthless. Not only does it not install nor does it update ANYTHING, but after using it 3-4 times, I now have a giant memory leak which kills my pc in about 3 hours. Thank god for Timeshift.
    – Nate T
    Nov 15, 2021 at 7:06

3 Answers 3

22

Using the nvm (node version manager) is the best option to update the default version of node.

  1. install or update nvm:

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
    

    or

    wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
    
  2. After successful installation, close the terminal and open a new terminal. List the version of nodejs available:

    nvm ls-remote
    

    This will list the available versions of nodejs.

  3. Select the version you want to install:

    nvm install xxxxxx
    
  4. Check the version:

    node -v
    

Hope this helps as a step by step guide.

1
  • 1
    Nice answer, exactly what I wanted! Aug 12, 2017 at 9:38
8

In the end I was sick of getting nowhere.

As a fix, I decided to use nvm (node version manager).

It's super simple to install, setup and use. Took less than 3 minutes to get back up and running with nodejs version 5.

https://github.com/creationix/nvm

I'm writing this for completeness.

1
  • 1
    Awesome! Glad you found something that works. NVM is my preferred way of installing Node on Ubuntu as well. Dec 31, 2015 at 15:23
3

I always use n to do update, upgrade and remove node versions. Note that you might have to use sudo, depending on your configuration.

$ npm install -g n

Use or install the latest official release:

$ n latest

Use or install the stable official release:

$ n stable

Use or install the latest LTS official release:

$ n lts

Removing Versions

$ n rm 0.9.4 v0.10.0

You must log in to answer this question.

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