51

On Ubuntu 16.04, I mistakenly used root to install nvm, and then to install node.js 8.8.1 via nvm. I also used nvm alias default 8.8.1, thinking it would correct my error.

Now I would like to:

  1. Remove the default alias
  2. Uninstall node 8.8.1
  3. Uninstall npm 4.8.5, which came along with node
  4. Uninstall nvm
  5. Reinstall everything correctly for the right non-sudo user

It looks like I've succeeded with the first part:

# nvm unalias default
Deleted alias default - restore it with `nvm alias "default" "8.8.1"`

But nvm refuses to uninstall node 8.8.1, because it is the only version installed:

# nvm uninstall 8.8.1                                                                                                                             
nvm: Cannot uninstall currently-active node version, v8.8.1 (inferred from 8.8.1).

I am guessing that I first need to disactivate node 8.8.1, but I see nothing in the output of nvm --help which would appear to do this.

What steps do I need to take to completely remove node.js, npm and nvm from the machine before re-installing everything correctly?

James Newton
  • 6,623
  • 8
  • 49
  • 113
  • Same question: [node.js - nvm: Cannot uninstall currently-active node version](https://stackoverflow.com/q/38775287) – li ki Feb 03 '22 at 08:02

5 Answers5

101

In Terminal, First type

nvm deactivate

Then type

nvm uninstall 8.8.1
ph0en1x
  • 68
  • 1
  • 13
Shar
  • 1,026
  • 1
  • 8
  • 2
  • Thanks @Shar. That nvm deactivate works. But why do we need to deactivate. It is not something like database server like PostgreSQL? – Amit Tiwari Mar 20 '23 at 11:59
14
rm -Rf ~/.nvm

This is the nuclear option in my case. just -R would ask me if I really wanted to delete every file in the nvm folder.

8

You can uninstall the nodejs by using the following command.

yum remove nodejs

However, this will not remove the nvm from your linux box. To remove that try the below command.

nvm unload

Arul Deepan
  • 159
  • 2
  • 6
2
nvm deactivate

can temporarily deactivate the nvm'ed node. You can comment out the path in .zshrc etc, for the next session.

#export NVM_DIR="$HOME/.nvm"
#[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
#[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
goodhyun
  • 4,814
  • 3
  • 33
  • 25
0

I tried these commands for Ubuntu 20v and it removed node js completely

sudo apt-get remove nodejs
sudo apt-get autoremove

Then check version using, node --version and you will get this message,

bash: /usr/bin/node: No such file or directory
Rohit
  • 293
  • 3
  • 6