How can I completely uninstall nodejs, npm and node in Ubuntu 14.04
I wrongly installed "node" by running the command
sudo apt-get install node And later I installed nodejs (v0.10.37). I tried to update to v0.12 with npm but it keeps saying
0.10.37 when I run
nodejs -v. Also, I can't use the node command since I wrongly installed the other node thing before.
I think the main problem is that I still have the wrong node package and installing
nodejs-legacy doesn't work.
npm install command works and creates the folder with the files but my app still says that the libraries are missing.
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
.node folder in your home folder and delete those.
If you type
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.
Read more... Read less...
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
.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
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:
which should give this output:
Installing Node.js and npm
nvm install node nvm install --lts
Once the installation is completed, verify it by printing the Node.js version:
should give this output:
Npm should also be installed with node, verify it using
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:
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:
On the command line, update your system variables:
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 / -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/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
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).
which node, which will give a path something like
Run the command
sudo rm /usr/local/bin/nodeto remove the binary (adjust the path according to what you found in step 2). Now
node -vshows 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 -
sudo apt-get install nodejs
Note: If you are getting error like
node /usr/bin/env: node: No such file or directory
ln -s /usr/bin/nodejs /usr/bin/node
node -vwill give
Worked for me.
Try the following commands:
$ sudo apt-get install nodejs $ sudo apt-get install aptitude $ sudo aptitude install npm