ChatGPT解决这个技术问题 Extra ChatGPT

How can I completely uninstall nodejs, npm and node in Ubuntu [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions about general computing hardware and software on Stack Overflow. You can edit the question so it’s on-topic for Stack Overflow. Closed 1 year ago. Improve this question

The Question is similar to How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X) but for Ubuntu, and just for uninstalling.

Installation was done by: sudo apt-get install node

How do I completely remove npm along with all libraries, packages and any other files installed by npm on my system, via e.g. npm install -g @vue/cli?

I do plan to reinstall npm afterwards.

installing nodejs-legacy works if you first apt-get remove node (or better yet, purge). The node program is a ham radio software modem so unless you have a ham license and want to send digital packets over ham radio you don't need it.
yeah, I did it. Still I had problems. Everytime I wrote node in the console it would tell me something like /usr/sbin/ couldn't finde node or something like that.
Does this answer your question? Uninstall Node.JS using Linux command line?

Z
Zanna
sudo apt-get remove nodejs
sudo apt-get remove npm

Then go to /etc/apt/sources.list.d and remove any node list if you have. Then do a

sudo apt-get update

Check for any .npm or .node folder in your home folder and delete those.

If you type

which node

you can see the location of the node. Try which nodejs and which npm too.

I would recommend installing node using Node Version Manager(NVM). That saved a lot of headache for me. You can install nodejs and npm without sudo using nvm.


Adding to this, I will also suggest you to remove any 3rd part PPAs if you have added them. I was stuck at this problem, node was getting removed but still I was unable to install a newer version without using nvm
Only this worked for me! I just add the next command in the end: rm -rf usr/local/bin/npm
If you want to remove nvm too check this issue github.com/creationix/nvm/issues/298
answer above assumes that this was not installed using the node script and wget.... @zanna has name on both solutions, and the two should be combined
@LeeRuns I only edited them. I agree there is a lot of duplication on this post - I think three nearly identical answers have already been removed. I don't think I can do anything further with the tools available to me.
Z
Zanna

It is better to remove NodeJS and its modules manually because installation leaves a lot of files, links and modules behind and later this creates problems when we reconfigure another version of NodeJS and its modules.

To remove the files, run the following commands:

sudo rm -rf /usr/local/bin/npm 
sudo rm -rf /usr/local/share/man/man1/node* 
sudo rm -rf /usr/local/lib/dtrace/node.d
rm -rf ~/.npm
rm -rf ~/.node-gyp
sudo rm -rf /opt/local/bin/node
sudo rm -rf /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/include/node*
sudo rm -rf /usr/local/bin/node*

I have posted a step by step guide with commands on my blog: AMCOS IT Support For Windows and Linux: To completely uninstall node js from Ubuntu.


Perfect, I've just added "sudo rm -rf ~/.npm-global"
Under what circumstances would a system-installed Node write things in /opt, let alone then /usr/local?
Z
Zanna

Note: This will completely remove nodejs from your system; then you can make a fresh install from the below commands.

Removing Nodejs and Npm

sudo apt-get remove nodejs npm node
sudo apt-get purge nodejs

Now remove .node and .npm folders from your system

sudo rm -rf /usr/local/bin/npm 
sudo rm -rf /usr/local/share/man/man1/node* 
sudo rm -rf /usr/local/lib/dtrace/node.d 
sudo rm -rf ~/.npm 
sudo rm -rf ~/.node-gyp 
sudo rm -rf /opt/local/bin/node 
sudo rm -rf opt/local/include/node 
sudo rm -rf /opt/local/lib/node_modules  

sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/include/node*
sudo rm -rf /usr/local/bin/node*

Go to home directory and remove any node or node_modules directory, if exists.

You can verify your uninstallation by these commands; they should not output anything.

which node
which nodejs
which npm

Installing NVM (Node Version Manager) by downloading and running a script

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

The command above will clone the NVM repository from Github to the ~/.nvm directory:

Close and reopen your terminal to start using nvm or run the following to use it now:

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

As the output above says, you should either close and reopen the terminal or run the commands to add the path to nvm script to the current shell session. You can do whatever is easier for you.

Once the script is in your PATH, verify that nvm was properly installed by typing:

nvm --version

which should give this output:

0.34.0

Installing Node.js and npm

nvm install node
nvm install --lts

Once the installation is completed, verify it by printing the Node.js version:

node --version

should give this output:

v12.8.1

Npm should also be installed with node, verify it using

npm -v

should give:

6.13.4

Extra - [Optional] You can also use two different versions of node using nvm easily

nvm install 8.10.0 # just put the node version number Now switch between node versions

$ nvm ls
->     v12.14.1
        v13.7.0
default -> lts/* (-> v12.14.1)
node -> stable (-> v13.7.0) (default)
stable -> 13.7 (-> v13.7.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.14.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.18.1 (-> N/A)

In my case v12.14.1 and v13.7.0 both are installed, to switch I have to just use

nvm use 12.14.1

Configuring npm for global installations In your home directory, create a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

In your preferred text editor, open or create a ~/.profile file if does not exist and add this line:

PATH="$HOME/.npm-global/bin:$PATH"

On the command line, update your system variables:

source ~/.profile

That's all


This is the most comprehensive answer to removing old versions, and using NVM to make intalling the latest version easier.
If you face the error Provided file to checksum does not exist. Please view this answer
j
jokerdino

It bothered me too much while updating node version from 8.1.0 to 10.14.0

Here is what worked for me:

Open terminal (Ctrl+Alt+T). Type which node, which will give a path something like /usr/local/bin/node Run the command sudo rm /usr/local/bin/node to remove the binary (adjust the path according to what you found in step 2). Now node -v shows you have no node version Download a script and run it to set up the environment: curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - Install using sudo apt-get install nodejs Note: If you are getting error like node /usr/bin/env: node: No such file or directory just run ln -s /usr/bin/nodejs /usr/bin/node Source Now node -v will give v10.14.0

Worked for me.


j
jokerdino

I was crazy to delete node and npm and nodejs from my Ubuntu 14.04 but with this steps you will remove it:

sudo apt-get uninstall nodejs npm node
sudo apt-get remove nodejs npm node

If you uninstall correctly and it is still there, check these links:

Stack Overflow answer with more information

Remove npm - Official website

Stack Overflow answer for uninstalling if you installed via git repository

Try purging nodejs npm and node

You can also try using find:

find / -name "node"

Although since that is likely to take a long time and return a lot of confusing false positives, you may want to search only PATH locations:

find $(echo $PATH | sed 's/:/ /g') -name "node"

It would probably be in /usr/bin/node or /usr/local/bin. After finding it, you can delete it using the correct path, eg:

sudo rm /usr/bin/node

Z
Zanna

Those who installed node.js via the package manager can just run:

sudo apt-get purge nodejs

Optionally if you have installed it by adding the official NodeSource repository as stated in Installing Node.js via package manager, do:

sudo rm /etc/apt/sources.list.d/nodesource.list

If you want to clean up npm cache as well:

rm -rf ~/.npm

It is bad practice to try to remove things manually, as it can mess up the package manager, and the operating system itself. This answer is completely safe to follow


I don't like the manual way to delete things too. thank for this
S
Soroush Chehresa

Try the following commands:

$ sudo apt-get install nodejs
$ sudo apt-get install aptitude
$ sudo aptitude install npm

The main difference between your answer and the accepted answer from a few years ago is that you're going through Aptitude. It'd be useful to explain why you feel this is a better approach than the accepted answer. What does Aptitude provide that the earlier answers were lacking? Why should readers implement your approach?
Am I the only one who thought this is answering how to do the opposite of what the question is asking?