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

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years 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.

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.

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.

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

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.

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

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

Try the following commands:
$ sudo apt-get install nodejs
$ sudo apt-get install aptitude
$ sudo aptitude install npm

Related

Uninstalling node with homebrew [duplicate]

My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19.
My node version is:
node -v
v0.6.1-pre
NVM says this (after I install a version of node for the first time in one bash terminal):
nvm ls
v0.6.19
current: v0.6.19
But when I restart bash, this is what I see:
nvm ls
v0.6.19
current: v0.6.1-pre
default -> 0.6.19 (-> v0.6.19)
So where is this phantom node 0.6.1-pre version and how can I get rid of it? I'm trying to install libraries via NPM so that I can work on a project.
I tried using BREW to update before NVM, using brew update and brew install node.
I've tried deleting the "node" directory in my /usr/local/include and the "node" and "node_modules" in my /usr/local/lib.
I've tried uninstalling npm and reinstalling it following these instructions.
All of this because I was trying to update an older version of node to install the "zipstream" library. Now there's folders in my users directory, and the node version STILL isn't up to date, even though NVM says it's using 0.6.19.
Ideally, I'd like to uninstall nodejs, npm, and nvm, and just reinstall the entire thing from scratch on my system.
Apparently, there was a /Users/myusername/local folder that contained a include with node and lib with node and node_modules. How and why this was created instead of in my /usr/local folder, I do not know.
Deleting these local references fixed the phantom v0.6.1-pre. If anyone has an explanation, I'll choose that as the correct answer.
EDIT:
You may need to do the additional instructions as well:
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
which is the equivalent of (same as above)...
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp
or (same as above) broken down...
To completely uninstall node + npm is to do the following:
go to /usr/local/lib and delete any node and node_modules
go to /usr/local/include and delete any node and node_modules directory
if you installed with brew install node, then run brew uninstall node in your terminal
check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
go to /usr/local/bin and delete any node executable
You may also need to do:
sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d
Additionally, NVM modifies the PATH variable in $HOME/.bashrc, which must be reverted manually.
Then download nvm and follow the instructions to install node. The latest versions of node come with npm, I believe, but you can also reinstall that as well.
For brew users, OSX:
To remove:
brew uninstall node;
# or `brew uninstall --force node` which removes all versions
brew cleanup;
rm -f /usr/local/bin/npm /usr/local/lib/dtrace/node.d;
rm -rf ~/.npm;
To install:
brew install node;
which node # => /usr/local/bin/node
export NODE_PATH='/usr/local/lib/node_modules' # <--- add this ~/.bashrc
You can run brew info node for more details regarding your node installs.
consider using NVM instead of brew
NVM (node version manager) is a portable solution for managing multiple versions of node
https://github.com/nvm-sh/nvm
> nvm uninstall v4.1.0
> nvm install v8.1.2
> nvm use v8.1.2
> nvm list
v4.2.0
v5.8.0
v6.11.0
-> v8.1.2
system
you can use this with AVN to automatically switch versions as you hop between different projects with different node dependencies.
UPDATE: 23 SEP 2016 - Intel Macs 10.11.x and above
If you're afraid of running these commands...
Thanks to jguix for this quick tutorial.
First, create an intermediate file:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom >> ~/filelist.txt
Manually review your file (located in your home ~ folder)
~/filelist.txt
Then delete the files:
cat ~/filelist.txt | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
Intel Macs 10.10.x and below
Thanks Lenar Hoyt
Gist Comment Source: gistcomment-1572198
Original Gist: TonyMtz/d75101d9bdf764c890ef
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
ORIGINAL: 7 JUL 2014
I know this post is a little dated but just wanted to share the commands that worked for me in Terminal when removing Node.js.
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
On Mavericks I install it from the node pkg (from nodejs site) and I uninstall it so I can re-install using brew. I only run 4 commands in the terminal:
sudo rm -rf /usr/local/lib/node_modules/npm/
brew uninstall node
brew doctor
brew cleanup --prune-prefix
If there is still a node installation, repeat step 2. After all is ok, I install using brew install node
https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/
Run following commands to remove node completely from system in MACOS
sudo rm -rf ~/.npm ~/.nvm ~/node_modules ~/.node-gyp ~/.npmrc ~/.node_repl_history
sudo rm -rf /usr/local/bin/npm /usr/local/bin/node-debug /usr/local/bin/node /usr/local/bin/node-gyp
sudo rm -rf /usr/local/share/man/man1/node* /usr/local/share/man/man1/npm*
sudo rm -rf /usr/local/include/node /usr/local/include/node_modules
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/lib/dtrace/node.d
sudo rm -rf /opt/local/include/node /opt/local/bin/node /opt/local/lib/node
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/share/systemtap/tapset/node.stp
brew uninstall node
brew doctor
brew cleanup --prune-prefix
After this I will suggest to use following command to install node using nvm (check https://github.com/nvm-sh/nvm for latest version)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
from https://github.com/nvm-sh/nvm
Why nvm?
this is a good question, there will be projects requiring different versions of node, i.e. A requires node version 12 while B requires node version 14. This version management of node is provided by nvm only.
I have summarized the existing answers and made sure Node.js is COMPLETELY ERASED along with NPM.
Lines to copy to terminal:
brew uninstall node;
which node;
sudo rm -rf /usr/local/bin/node;
sudo rm -rf /usr/local/lib/node_modules/npm/;
brew doctor;
brew cleanup --prune-prefix;
First:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
go to /usr/local/include and delete any node and node_modules directory
cd /usr/local/include
sudo rm -rf node*
if you installed with brew install node, then run brew uninstall node in your terminal
brew uninstall node
check your Home directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there
go to /usr/local/bin and delete any node executable
cd /usr/local/bin
sudo rm -rf /usr/local/bin/npm
ls -las
You may need to do the additional instructions as well:
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
Source: tonyMtz
downgrade node to 0.10.36
sudo npm cache clean -f
sudo npm install -g n
sudo n 0.10.36
upgrade node to stable v
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
I'm not sure if it's because I had an old version (4.4.5), or if it's because I used the official installer, but most of the files referenced in other answers didn't exist on my system. I only had to remove the following:
~/.node-gyp
~/.node_repl_history
/usr/local/bin/node
/usr/local/bin/npm
/usr/local/include/node
/usr/local/lib/dtrace/node.d
/usr/local/lib/node_modules
/usr/local/share/doc/node
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
I decided to keep ~/.npm because I was planning on reinstalling Node with Homebrew.
Complete uninstall Node.js on macOS Monterey version 12.0.1
To check the current node version installed on your system:
# node -v
# v14.15.0
Enter the given below commands to delete Node from your system:
# cd /usr/local/include
# sudo rm -R node
# cd ../lib
# sudo rm -R node_modules
# cd ../bin
# sudo rm -R node
to check that node doesn't exist anymore
# node -v
# -bash: node: command not found
Install Node.js on macOS Monterey version 12.0.1
Download the LTS version of node from the official website
Double click on the node-v16.13.1.pkg installation package and continue with the default settings
Type node -v in your terminal to print the current installed version of node : v16.13.1 & npm -v to print the current npm version installed on your machine : 8.1.2
Complete uninstall Nodejs on macOS Big Sur version 11.2.3 (20D91)
Introduction
First things first, I want to say thank you for sharing this trick #tonymtz.
My system is running macOS Big Sur version 11.2.3 (20D91) with nodejs Latest Current Version: 15.14.0 (includes npm 7.7.6) installed from the official website.
I tried to fully uninstall nodejs on my MacBook Pro in order to re-install it with homebrew package manager using:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
but I was facing an issue like #AhteshamShah mentioned in #JohelAlvarez's answer:
When fired first command getting: can't open /var/db/receipts/org.nodejs.pkg.bom: No such file or directory **** Can't open /var/db/receipts/org.nodejs.pkg.bom.
– Ahtesham Shah Jun 20 '19 at 5:09
I dived into the original post linked by #JohelAlvarez, reading all the comments and I've found this comment from #e2tha-e:
#tonymtz On my installation of Node v4.0.0 on Yosemite 10.10.5, the first line needed to be
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
A different filename from org.nodejs.pkg.bom
Otherwise, this worked like a charm!
#e2tha-e was right, on macOS Big Sur version 11.2.3 (20D91) with nodejs Latest Current Version: 15.14.0 (includes npm 7.7.6) installed from official website, the file name is not org.nodejs.pkg.bom but org.nodejs.node.pkg.bom .
You can check this when you cd /var/db/receipts/ && ls -la.
Solution for installation from Nodejs's official website
With your preferred Terminal, fully uninstall Nodejs from your system like this :
Option 1
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
Option 2
Go to /var/db/receipts/ and delete any org.nodejs.*
cd /var/db/receipts/ && ls -la
sudo rm -rf org.nodejs.*
Go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib && ls -la
sudo rm -rf node*
Go to /usr/local/include and delete any node and node_modules directory
cd /usr/local/include && ls -la
sudo rm -rf node*
Check your $HOME directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there.
Go to /usr/local/bin and delete any node executable
cd /usr/local/bin && ls -la
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/node
You may need to do this too:
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
After that, you can check if there is still node in your system with which node or find all occurrences for node in your system.
Tips
Search where node files are with find / -name 'node' | sed -E 's|/[^/]+$||' |sort -u
Before running shared code by others, check your directories before to make sure you write the right file name.
Steps to Uninstall NodeJS:
For MacOS Monterey with M1 chip, please follow the link below to uninstall node completely from the system. I have tried multiple ways but this one worked finally.
Uninstall NodeJS & NPM from Mac M1 Monterey
Additionally, please execute the following commands at the end to remove node related directories from bin folder.
sudo rm -R node-sass
sudo rm -R npm
sudo rm -R npx
To verify that node is removed:
node --version
It should say command not found.
Steps to Install NodeJS:
Enable Rosseta terminal on your Mac with M1 chip.
How to enable Rosseta terminal
Use nvm (Node Version Manager) to install NodeJS on your machine. Why nvm?? Because you can run multiple versions of NodeJS (you can work with a new app as well as a Legacy app).
How to install multiple versions of NodeJS using nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Create a .zshrc file if not exists.
touch ~/.zshrc
Install node using nvm.
nvm install node # "node" is an alias for the latest version
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
To verify the number of NodeJS versions available:
nvm ls
After
brew uninstall node
I had to know which node
which node
then remove that
rm -rf /usr/local/bin/node
Delete node and/or node_modules from /usr/local/lib
ex code:
cd /usr/local/lib
sudo rm -rf node
sudo rm -rf node_modules
Delete node and/or node_modules from /usr/local/include
Delete node, node-debug, and node-gyp from /usr/local/bin
Delete .npmrc from your home directory (these are your npm settings, don't delete this if you plan on re-installing Node right away)
Delete .npm from your home directory
Delete .node-gyp from your home directory
Delete .node_repl_history from your home directory
Delete node* from /usr/local/share/man/man1/
Delete npm* from /usr/local/share/man/man1/
Delete node.d from /usr/local/lib/dtrace/
Delete node from /usr/local/opt/local/bin/
Delete node from /usr/local/opt/local/include/
Delete node_modules from /usr/local/opt/local/lib/
Delete node from /usr/local/share/doc/
Delete node.stp from /usr/local/share/systemtap/tapset/
Worked for me.
$node --version
v11.1.0
$nvm deactivate
$nvm uninstall v11.1.0
If you have already installed nvm then execute the following commands
nvm deactivate - This will remove /.nvm/*/bin from $PATH
nvm list - To list out all the versions of node installed in the system
nvm uninstall <version> in you can specify all the versions you want to uninstall.
It is always a good that you install node using nvm and uninstall using nvm
rather than brew .
This solution worked for me.
Additional Commands
which node to know the path of node installed in your system. You can rm this directory to uninstall node manually. Then you may need to adjust the PATH file accordingly.
Expanding on Dominic Tancredi's awesome answer, I've rolled this into a bash package and stand-alone script. If you are already using the "Back Package Manager" called bpkg you can install the script by running:
bpkg install -g brock/node-reinstall
Or you can have a look at the script on Github at brock/node-reinstall. The script allows you to re-install node using nvm or nave, and to specify a node version as your default.
Additional to the main answer I needed to remove all npm instances found in:
rm -rf /usr/local/share/man/man1/npm*
maybe you need to make
hash -r
it helps with problem of symlink
$ node -v
$ bash: /opt/local/bin/node: No such file or directory
The best way is to download an installer package: .pkg on mac. Prefer the latest stable version.
Here is the link: Node.js
This package will eventually overwrite the previous version and set environment variables accordingly. Just run the installer and its done within a few clicks.
I have been hit by an issue during uninstall of Node.js on my mac. I had some strange behavior like npm is still there even after having to remove it with all this.
It was because I had an old install done with macport. So you also have to uninstall it using port:
sudo port uninstall nodejs
It may have installed many different versions of Node.js so uninstall them all (one by one).
You can clone https://github.com/brock/node-reinstall and run the simple command as given in the repository.After that just restart your system.
This is the simplest method and also worked for me.
I had installed Node.js from source downloaded from the git repository. I installed with:
./configure
$ make
$ sudo make install
Because the make file supports it, I can do:
$ sudo make uninstall
As a companion to the answers explaining cleanup and install via homebrew, I found that homebrew itself provided clear indications of the symlink clashes.
Unfortunately it provides these one by one as it encounters them, so it is a little laborious, but it does seem to find all the clashes and was the only way I could get a clean install with homebrew.
Essentially, the process is:
use homebrew to uninstall node
clean homebrew
use homebrew to install node and note any flagged clashing file
delete the flag clashing file (or whole directory if it is a 'node' directory)
goto step 1 until you get a clean install
:
Here is a screen output from the last steps of my install - you can see it results in a clean install (eventually...):
computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/systemtap/tapset/node.stp
Target /usr/local/share/systemtap/tapset/node.stp
already exists. You may want to remove it:
rm '/usr/local/share/systemtap/tapset/node.stp'
To force the link and overwrite all conflicting files:
brew link --overwrite node
To list all files that would be deleted:
brew link --overwrite --dry-run node
Possible conflicting files are:
/usr/local/share/systemtap/tapset/node.stp
/usr/local/lib/dtrace/node.d
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ rm '/usr/local/share/systemtap/tapset/node.stp'
computer1:DevResources user1$ brew uninstall node
Uninstalling /usr/local/Cellar/node/13.1.0... (4,591 files, 54.2MB)
computer1:DevResources user1$ brew cleanup
computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink lib/dtrace/node.d
Target /usr/local/lib/dtrace/node.d
already exists. You may want to remove it:
rm '/usr/local/lib/dtrace/node.d'
To force the link and overwrite all conflicting files:
brew link --overwrite node
To list all files that would be deleted:
brew link --overwrite --dry-run node
Possible conflicting files are:
/usr/local/lib/dtrace/node.d
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ rm '/usr/local/lib/dtrace/node.d'
computer1:DevResources user1$
computer1:DevResources user1$ brew uninstall node
Uninstalling /usr/local/Cellar/node/13.1.0... (4,591 files, 54.2MB)
computer1:DevResources user1$ brew cleanup
computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ node -v
v13.1.0
First of all, you need to deactivate node: (mac) after install new node version.
nvm deactivate
This is removed /Users/user_name/.nvm/*/bin from $PATH
And after that node was updated
node --version
v10.9.0
In my case none of the other answers worked because I previously downgraded to node8. So instead of doing above, following worked for me:
which node
which returned /usr/local/bin/node#8 instead of /usr/local/bin/node
so i executed this command:
brew uninstall node#8
which worked and then downloaded latest pkg from official site and installed. After that I had to close my terminal and start again to access new version
Docker - alternative approach
Docker is some-kind of super-fast virtual machine which can be use to run tools like node (instead install them directly on mac-os). Advantages to do it are following
all stuff ('milions' node files) are install inside docker image/container (they encapsulated in few inner-docker files)
you can map your mac directory with project to your docker container and have access to node - but outside docker, mac-os sytem don't even know that node is installed. So you get some kind of 'virtual' console with available node commands which can works on real files
you can easily kill node by find it by docker ps and kill by docker rm -f name_or_num
you can easily uninstall docker image/containers by one command docker rmi ... and get free space - and install it again by run script (below)
your node is encapsulated inside docker and don't have access to whole system - only to folders you map to it
you can run node services and easily map they port to mac port and have access to it from web browser
you can run many node versions at the same time
in similar way you can install other tools like (in many versions in same time): php, databases, redis etc. - inside docker without any interaction with mac-os (which not notice such software at all). E.g. you can run at the same time 3 mysql db with different versions and 3 php application with different php version ... - so you can have many tools but clean system
TEAM WORK: such enviroment can be easily cloned into other machines (and even to windows/linux systems - with some modifications) and provide identical docker-level environment - so you can easily set up and reuse you scripts/dockerfiles, and setup environment for new team member in very fast way (he just need to install docker and create similar folder-structure and get copy of scripts - thats all). I work this way for 2 year and with my team - and we are very happy
Instruction
Install docker using e.g. this instructions
Prepare 'special' directory for work e.g. my directory is /Users/kamil/work (I will use this directory further - but it can be arbitrary) - this directory will be 'interface' between docker containers and your mac file ststem. Inside this dir create following dir structure:
/Users/kamil/work/code - here you put your projects with code
/Users/kamil/work/tools
/Users/kamil/work/tools/docker-data - here we map containers output data like logs (or database files if someone ouse db etc.)
/Users/kamil/work/tools/docker
/Users/kamil/work/tools/docker/node-cmd - here we put docker node scripts
inside tools create file .env which will contain in one place global-paths used in other scripts
toolspath="/Users/kamil/work/tools"
codepath="/Users/kamil/work/code"
workpath=/Users/kamil/work
innside dir ../node-cmd create file dockerfile with following content
# default /var/www/html (mapped to .../code folder with projects)
FROM node
WORKDIR /work
# Additional arbitrary tools (ng, gulp, bower)
RUN npm install -g n #angular/cli bower gulp grunt
CMD while true; do sleep 10000; done
# below ports are arbitrary
EXPOSE 3002 3003 3004 4200
innside dir ../node-cmd create file run-container with following content (this file should be executable e.g. by chmod +x run-container) - (notice how we map port-s and directories form external 'world' to internal docker filesystem)
set -e
cd -- "$(dirname "$0")" # this script dir (not set on doubleclick)
source ../../.env
toolsdir=$toolspath/docker-data
workdir=$workpath
if [ ! "$(docker ps | grep node-cmd)" ]
then
docker build -t node-cmd .
docker rm -f node-cmd |:
docker run -d --name node-cmd -p 4200:4200 -p 4201:4201 -p 3002:3002 -p 3003:3003 -p 3004:3004 -v $toolsdir/node-cmd/logs:/root/.npm/_logs -v $workdir:/work node-cmd
fi
ok now you can add some project e.g. work/code/myProject and add to it following file 'run-cmd' (must be executable)
cd -- "$(dirname "$0")"
../../tools/docker/node-cmd/run-container
docker exec -it node-cmd bash -c "cd /work/code/myProject; bash"
then if you run above script (by double-click), you will see console with available node commands in project directory e.g. npm install
to run project in background (e.g some serwice) e.g. run web-server angular-cli application you can use following script (named run-front -must be executable) - (you must also edit /etc/hosts file to add proper domain)
cd -- "$(dirname "$0")"
open "http://my-angular.local:3002"
../../tools/docker/node-cmd/run-container
docker exec -it node-cmd /bin/sh -c "cd /work/code/my-angular-project; npm start"
cat # for block script and wait for user ctrl+C
If you're unable to locate node just run whereis node and whereis npm and whereis nvm and you can remove the listed directories as needed.
You'll also need to entirely close your terminal and reopen it for changes to take effect.
This fixed it for me Fixing npm On Mac OS X for Homebrew Users. And it does not require too many steps.
Just go to the solution part if you don't care about the why.
Here is the relevant part for convenience:
Solution
This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.
Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.
Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the correct defaults, configure the location for global npm modules to be installed, and then install npm as its own package.
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
Node and npm should be correctly installed at this point. The final step is to add ~/.npm-packages/bin to your PATH so npm and global npm packages are usable. To do this, add the following line to your ~/.bash_profile:
export PATH="$HOME/.npm-packages/bin:$PATH"
Now you can re-install any global npm packages you need without any problems.
#lfender6445 answer worked just fine for me to uninstall
Now to re-install, I had problems installing the last version instead of the most stable one, so to install a specific node version you should do:
brew install node#10 // 10 is the version I want
brew link node#10

npm update broke npm

I just followed this guide to update npm (as my nodered camera module wasn't working) and ran
npm install -g npm
but now my npm install seems completely broken. If I just type
npm
or
npm update
I get
/usr/local/lib/node_modules/npm/bin/npm-cli.js:79
let notifier = require('update-notifier')({pkg})
^^^
SyntaxError: Block-scoped declarations (let, const, function, class)
not yet supported outside strict mode
I've tried
sudo apt-get remove npm
sudo apt-get install npm
but the reinstall didn't help.
I think my node version needs upgrading from v4.8.2 but I thought that was only possible with npm?
You probably have npm installed twice, one is in /usr/local/bin and the other in /usr/bin.
First, you can try to remove the npm module that has been installed by upgrading npm. Try to run this:
rm -r /usr/local/lib/node_modules/npm
/usr/bin/npm uninstall npm
Once you have a running version of npm, install a more recent version of node before upgrading npm. Then, remove the version of your linux distribution.
If the first solution doesn't work, another approach is to install a recent version of node (without using npm of course):
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
(solution for centos....I assume it would work also on ubuntu):
to clean up completely my centos machine, I have additionally done the following - my user is "centos" and my home is /home/centos:
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/npx
sudo rm -rf /usr/lib/node_modules/
sudo rm -rf /usr/bin/npm
sudo rm -r /usr/local/lib/node_modules/
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/bin/npm
sudo rm -rf /usr/lib/node_modules/
rm -rf /home/centos/.npm/
rm -rf /home/centos/node*
rm -rf /home/centos/.node-gyp/
sudo rm -rf /root/.npm/
sudo rm /usr/bin/node
sudo rm -rf /usr/local/include/node
only at this point I reinstalled again:
wget http://nodejs.org/dist/latest/node-v11.4.0-linux-x64.tar.gz
sudo tar --strip-components 1 -xzvf node-v* -C /usr/local
and things are working again:
node --version
v11.4.0
npm --version
6.4.1
To those who used google to find this, you may be tempted to install via
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - and then installing with sudo apt install nodejs.
However, I somehow ran into this issue regardless. Please keep in mind that npm#6 dropped support for node#<=4, and that is a contributing factor here. If you want to be sure that everything is installed at the latest, correct versions, I very highly recommend installing through nvm.
Via the nvm instructions on their GitHub: You can add the install script with
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
Then you can start using nvm. You will likely have to restart your terminal, so after installation, exit the terminal, start it up again, and check that nvm is installed with nvm --version.
If everything goes well, you can install any specific version of node with npm in tow. The latest stable version of node as of writing this is 10.15.3, so
nvm install 10.15.3
And of course, if you need help, nvm --help has a list of options.
If you are using nvm to install npm and node, try this solution.
Get to know where exactly is the currently used node and npm is installed:
which node
In my case, it was /home/ubuntu/.nvm/versions/node/
Now, delete all the versions of node using:
sudo rm -rf /home/ubuntu/.nvm/versions/node/
You can now use nvm to install your required version of node and npm.
nvm install 4.9.1
Other answers didn't work for me on Ubuntu and ended up in a dead end, with a broken npm or unable to reinstall/update npm.
The radical solution I used :
1/ Remove all traces of node. Follow this page, using the remove.sh script at the bottom :
http://kselax.ru/en/npm-errors/
2/ Then reinstall from scratch nodejs + npm using the latest install script :
https://github.com/nodesource/distributions/blob/master/README.md
For me, reinstalling npm worked:
npm install -g npm

npm Cannot find module 'minimatch'

I update my Node.js to 5.5.0.
But it does not work when i use npm.
It reports error:
Cannot find module 'minimatch'.
But Node.js version 4.2 is ok on my mac.
Remove this folder /usr/local/lib/node_modules/npm/node_modules/rimraf/node_modules
rm -rf /usr/local/lib/node_modules/npm/node_modules/rimraf/node_modules
This happened to me when I updated my node through the binary but also had a previous version installed through homebrew .
The way I resolved this was, uninstalling node and npm completely and reinstalling using the binary found on their website .
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
brew unlink nodejs
and reinstall .
I ran into probably the same exact problem as you.
I went from 4.2.3 LTS to 5.9, and all npm functionality ceased, always generating that error.
I had to do the following:
Uninstall Node
Save anything in your node installation folder that you may want to keep
Completely delete the node installation
Re-install 5.9
Everything was tip-top after that. I purged the folder after I noticed that there was the old 4.2.3 installer in the Installer directory. I didn't know what the ramifications of that were, but better safe than sorry.

What is the recommended way to install Node.js, nvm and npm on MacOS X?

I am trying to use Homebrew as much as possible. What's the recommended way to install Node.js, nvm and npm on MacOS X?
Using homebrew install nvm:
brew update
brew install nvm
source $(brew --prefix nvm)/nvm.sh
Add the last command to the .profile, .bashrc or .zshrc file to not run it again on every terminal start. So for example to add it to the .profile run:
echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.profile
If you have trouble with installing nvm using brew you can install it manually (see here)
Using nvm install node or iojs (you can install any version you want):
nvm install 0.10
# or
nvm install iojs-1.2.0
npm is shipping with node (or iojs), so it will be available after installing node (or iojs). You may want to upgrade it to the latest version:
$ npm install -g npm#latest
UPD Previous version was npm update -g npm. Thanks to #Metallica for pointing to the correct way (look at the comment bellow).
Using npm install ionic:
npm install -g ionic
What about ngCordova: you can install it using npm or bower. I don't know what variant is more fit for you, it depends on the package manager you want to use for the client side. So I'll describe them both:
Using npm: Go to your project folder and install ng-cordova in it:
npm install --save ng-cordova
Using bower: Install bower:
npm install -g bower
And then go to your project folder and install ngCordova in it:
bower install --save ngCordova
PS
Some commands may require superuser privilege
Short variant of npm install some_module is npm i some_module
Use nvm to install Node.js, not Homebrew
In most of the answers, the recommended way to install nvm is to use Homebrew.
Don't do this.
On nvm's Github Readme is clearly says:
Homebrew installation is not supported. If you have issues with homebrew-installed nvm, please brew uninstall it, and install it using the instructions below, before filing an issue.
Use the following method instead
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
The script clones the nvm repository to ~/.nvm and adds the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
And then use nvm to install node. For example to install latest LTS version do:
nvm install 16
Clean and hassle free. It will set this as your default Node.js version as well so you should be all set.
I'm using n (Node version management)
You can install it in two ways
brew install n
or
npm install -g n
You can switch between different version of node and io. Here's an example from my current env when I call n without params:
$ n
io/3.3.1
node/0.12.7
node/4.0.0
node/5.0.0
ο node/5.10.1
I'm super late to this but I didn't like the other answers
Installing Homebrew
For brew run
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Installing node & npm
You SHOULD NOT use brew to install node and npm.
I've seen a few places suggested that you should use Homebrew to install Node (like alexpods answer and in this Team Treehouse blog Post) but installing this way you're more prone to run into issues as npm and brew are both package managers and you should have a package manager manage another package manager this leads to problems, like this bug offical npm issues Error: Refusing to delete: /usr/local/bin/npm or this Can't uninstall npm module on OSX
You can read more on the topic in DanHerbert's post Fixing npm On Mac OS X for Homebrew Users, where he goes on to say
Also, using the Homebrew installation of npm will require you to use sudo when installing global packages. Since one of the core ideas behind Homebrew is that apps can be installed without giving them root access, this is a bad idea.
For Everything else
I'd use npm; but you really should just follow the install instruction for each modules following the directions on there website as they will be more aware of any issue or bug they have than anyone else
If you have previously installed node using brew, then you will have a bunch of extra files that you should clean up before installing node "the right way". Plus, I had to add a few settings to my startup script to make things work smoothly.
I wrote a script to make this easy.
# filename: install-nvm-npm-node
# author: Lex Sheehan
# purpose: To cleanly install NVM, NODE and NPM
# dependencies: brew
NOW=$(date +%x\ %H:%M:%S)
CR=$'\n'
REV=$(tput rev)
OFF=$(tput sgr0)
BACKUP_DIR=$HOME/backups/nvm-npm-bower-caches/$NOW
MY_NAME=$(basename $0)
NODE_VER_TO_INSTALL=$1
if [ "$NODE_VER_TO_INSTALL" == "" ]; then
NODE_VER_TO_INSTALL=v0.12.2
fi
if [ "`echo "$NODE_VER_TO_INSTALL" | cut -c1-1`" != "v" ]; then
echo """$CR""Usage: $ $MY_NAME <NODE_VERSION_TO_INSALL>"
echo "Example: $ $MY_NAME v0.12.1"
echo "Example: $ $MY_NAME $CR"
exit 1
fi
echo """$CR""First, run: $ brew update"
echo "Likely, you'll need to do what it suggests."
echo "Likely, you'll need to run: $ brew update$CR"
echo "To install latest node version, run the following command to get the latest version: $ nvm ls-remote"
echo "... and pass the version number you want as the only param to $MY_NAME. $CR"
echo "Are you ready to install the latest version of nvm and npm and node version $NODE_VER_TO_INSTALL ?$CR"
echo "Press CTL+C to exit --or-- Enter to continue..."
read x
echo """$REV""Uninstalling nvm...$CR$OFF"
# Making backups, but in all likelyhood you'll just reinstall them (and won't need these backups)
if [ ! -d "$BACKUP_DIR" ]; then
echo "Creating directory to store $HOME/.nvm .npm and .bower cache backups: $BACKUP_DIR"
mkdir -p $BACKUP_DIR
fi
set -x
mv $HOME/.nvm $BACKUP_DIR 2>/dev/null
mv $HOME/.npm $BACKUP_DIR 2>/dev/null
mv $HOME/.bower $BACKUP_DIR 2>/dev/null
{ set +x; } &>/dev/null
echo "$REV""$CR""Uninstalling node...$CR$OFF"
echo "Enter your password to remove user some node-related /usr/local directories"
set -x
sudo rm -rf /usr/local/lib/node_modules
rm -rf /usr/local/lib/node
rm -rf /usr/local/include/node
rm -rf /usr/local/include/node_modules
rm /usr/local/bin/npm
rm /usr/local/lib/dtrace/node.d
rm -rf $HOME/.node
rm -rf $HOME/.node-gyp
rm /opt/local/bin/node
rm /opt/local/include/node
rm -rf /opt/local/lib/node_modules
rm -rf /usr/local/Cellar/nvm
brew uninstall node 2>/dev/null
{ set +x; } &>/dev/null
echo "$REV""$CR""Installing nvm...$CR$OFF"
echo "++brew install nvm"
brew install nvm
echo '$(brew --prefix nvm)/nvm.sh'
source $(brew --prefix nvm)/nvm.sh
echo "$REV""$CR""Insert the following line in your startup script (ex: $HOME/.bashrc):$CR$OFF"
echo "export NVM_DIR=\"\$(brew --prefix nvm)\"; [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\"$CR"
NVM_DIR="$(brew --prefix nvm)"
echo """$CR""Using nvm install node...$CR"
echo "++ nvm install $NODE_VER_TO_INSTALL"
nvm install $NODE_VER_TO_INSTALL
NODE_BINARY_PATH="`find /usr/local/Cellar/nvm -name node -type d|head -n 1`/$NODE_VER_TO_INSTALL/bin"
echo "$REV""$CR""Insert the following line in your startup script (ex: $HOME/.bashrc) and then restart your shell:$CR$OFF"
echo "export PATH=\$PATH:$NODE_BINARY_PATH:$HOME/.node/bin"
echo """$CR""Upgrading npm...$CR"
echo '++ install -g npm#latest'
npm install -g npm#latest
{ set +x; } &>/dev/null
echo "$REV""$CR""Insert following line in your $HOME/.npmrc file:$OFF"
echo """$CR""prefix=$HOME/.node$CR"
echo "Now, all is likley well if you can run the following without errors: npm install -g grunt-cli$CR"
echo "Other recommended global installs: bower, gulp, yo, node-inspector$CR"
I wrote a short article here that details why this is "the right way".
If you need to install iojs, do so using nvm like this:
nvm install iojs-v1.7.1
To install brew, just see its home page.
See alexpods answer for the rest.
You should install node.js with nvm, because that way you do not have to provide superuser privileges when installing global packages (you can simply execute "npm install -g packagename" without prepending 'sudo').
Brew is fantastic for other things, however. I tend to be biased towards Bower whenever I have the option to install something with Bower.
Here's what I do:
curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
cd / && . ~/.nvm/nvm.sh && nvm install 0.10.35
. ~/.nvm/nvm.sh && nvm alias default 0.10.35
No Homebrew for this one.
nvm soon will support io.js, but not at time of posting: https://github.com/creationix/nvm/issues/590
Then install everything else, per-project, with a package.json and npm install.
I agree with noa -- if you need to have multiple versions of node, io.js then brew is not the appropriate solution.
You can help beta-test io.js support in nvm: https://github.com/creationix/nvm/pull/616
If you just want io.js and are not switching versions, then you can install the binary distribution of io.js from https://iojs.org/dist/v1.0.2/iojs-v1.0.2-darwin-x64.tar.gz ; that includes npm and you will not need nvm if you are not switching versions.
Remember to update npm after installing: sudo npm install -g npm#latest
For install with zsh and Homebrew:
brew install nvm <=== This is not recommended by NVM. They want to run their shell script instead
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Then Add the following to ~/.zshrc or your desired shell
configuration file:
export NVM_DIR="$HOME/.nvm"
. "/usr/local/opt/nvm/nvm.sh"
Then install a node version and use it.
nvm install 7.10.1
nvm use 7.10.1
2021 Update
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Troubleshooting for MAC:
Since macOS 10.15, the default shell is zsh and nvm will look for .zshrc to update, none is installed by default. Create one with touch ~/.zshrc and run the install script again.
If you use bash, the previous default shell, run touch ~/.bash_profile to create the necessary profile file if it does not exist.
You might need to restart your terminal instance or run . ~/.nvm/nvm.sh. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration.
You have previously used bash, but you have zsh installed. You need to manually add these lines to ~/.zshrc and run . ~/.zshrc.

Uninstall Node.JS using Linux command line?

How do you uninstall node.js using the cmd line in linux?
For Ubuntu 12.04:
sudo apt-get remove nodejs
This will uninstall nodejs as well as npm.
Edit: If you know which package manager was used to install, it is best to uninstall with the same package manager. Examples for apt, make, yum are in other answers.
This is a manual approach:
Running which node will return something like /path/bin/node.
Then run cd /path
This is all that is added by Node.JS.
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Now the only thing I don't know about is npm and what it has installed. If you install npm again into a custom path that starts off empty, then you can see what it adds and then you will be able to make a list for npm similar to the above list I made for node.
If you installed from source, you can issue the following command:
sudo make uninstall
If you followed the instructions on https://github.com/nodejs/node/wiki to install to your $HOME/local/node, then you have to type the following before the line above:
./configure --prefix=$HOME/local/node
Sorry the answer of George Bailey does work very fine when you
want absolutely remove the node from your machine.
This answer is referred from : #tedeh
https://github.com/nodesource/distributions/issues/486
If you wanna install a new version of node you have to use the code below
sudo rm -rf /var/cache/yum
sudo yum remove -y nodejs
sudo rm /etc/yum.repos.d/nodesource*
sudo yum clean all
And add new nodejs version to "yum" an new version of node
#using this command for Node version 8
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
#using this command for Node version 10
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
Install nodejs
sudo yum -y install nodejs
I hope it gonna help you guy!!!
To uninstall node I followed the accepted answer by #George, as I no longer have the sources, but before doing so I ran:
sudo npm rm npm -g
That seemed to get rid of npm from the system directories such as /usr/bin/npm and /usr/lib/npm. I got the command from here. I then found a ~/.npm directory, which I deleted manually. Honestly I don't know if every trace of npm has been removed, but I can't find anything else.
If you installed node using curl + yum:
sudo curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
sudo yum -y install nodejs
Then you can remove it using yum:
sudo yum remove nodejs
Note that using the curl script causes the wrong version of node to be installed. There is a bug that causes node v6.7 to be installed instead of v4.x intended by the path (../setup_4.x) used in the curl script.
This is better to remove NodeJS and its modules manually because installation leaves a lot of files, links and modules behind and later it create problems while we reconfigure another version of NodeJS and its modules.
Run the following commands.
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /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*
and this done.
A step by step guide with commands is at http://amcositsupport.blogspot.in/2016/07/to-completely-uninstall-node-js-from.html
This helped me resolve my problem.
I think Manoj Gupta had the best answer from what I'm seeing. However, the remove command doesn't get rid of any configuration folders or files that may be leftover. Use:
sudo apt-get purge --auto-remove nodejs
The purge command should remove the package and then clean up any configuration files. (see this question for more info on the difference between purge and remove). The auto-remove flag will do the same for packages that were installed by NodeJS.
See the accepted answer on this question for a better explanation.
Although don't forget to handle NPM! Josh's answer covers that.
The answer of George Bailey works fine.
I would just add the following flags and use sudo if needed:
sudo rm -rf bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node
if you want to just update node, there's a neat updater too
https://github.com/creationix/nvm
to use,
git clone git://github.com/creationix/nvm.git ~/.nvm
source ~/.nvm/nvm.sh
nvm install v0.4.1
I think this works, at least partially (have not investigated):
nvm uninstall <VERSION_TO_UNINSTALL>
eg:
nvm uninstall 4.4.5
If you have yum you could do:
yum remove nodesource-release* nodejs
yum clean all
And after that check if its deleted:
rpm -qa 'node|npm'
after installing using the "ROCK-SOLID NODE.JS PLATFORM ON UBUNTU" script, i get this output. Which tells you how to uninstall nodejs.
Done. The new package has been installed and saved to
/tmp/node-install/node-v0.8.19/nodejs_0.8.19-1_i386.deb
You can remove it from your system anytime using:
dpkg -r nodejs
Best way to go around this is to do it right from the BEGINNING:
INSTALL BREW
#HERE IS HOW: PASTE IN TERMINAL
sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
Then at the end of your .bashrc file(In your home directory press Ctrl + H)
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Then restart terminal so the modification to .bashrc are reloaded
TO INSTALL NODE
brew install node
TO CHECK VERSION
node -v
npm -v
TO UPDATE NODE
brew update
brew upgrade node
TO UNINSTALL NODE
brew uninstall node
To Remove nodejs installed in centos 8:
From your home directory, run the below command
sudo yum remove nodejs
Enter y to confirm your command
In addition to apt or yum removal, clean any residual files to avoid conflicts if you ever install a new version:
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*
For Centos 7 and 8
Remove NodeJS
sudo yum remove -y nodejs
sudo rm -rf /var/cache/yum
sudo rm /etc/yum.repos.d/nodesource*
sudo yum clean all
Remove residual files
whereis node
sudo rm -rfv /usr/bin/node /usr/local/bin/node /usr/share/man/man1/node.1.gz
sudo rm -rfv /usr/bin/npm /usr/local/bin/npm /usr/share/man/man1/npm.1.gz
sudo rm -rfv /usr/local/bin/npx
sudo rm -rfv /usr/local/lib/node*
sudo rm -rfv /usr/local/include/node*
sudo rm -rfv /usr/lib/node_modules/
Just remove these files. No need to do anything else.
rm -rf ~/.nvm
rm -rf ~/.npm
rm -rf ~/.bower

Resources