Как удалять node.js в Ubuntu Linux?
У меня на dev компьютере стоит Ubuntu 20.04 и NodeJS 14.xx
Решил обновиться до NodeJS 15.xx (она на днях уже стала доступна, это не LTS версия).
В мире JavaScript я можно сказать новичёк.
Есть не приятное «ощущение» что я, что-то не так делаю:
Установку NodeJS 14 делал согласно инструкциям с официального сайта:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt install -y nodejs
Для того чтобы обновиться на 15-ую версию, решил удалить сначала 14-ую весию:
sudo apt remove nodejs
В результате выполнения команды, получил такие предупреждения:
Reading package lists. Done Building dependency tree Reading state information. Done The following package was automatically installed and is no longer required: libutempter0 Use 'sudo apt autoremove' to remove it. The following packages will be REMOVED: nodejs 0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded. After this operation, 120 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database . 225795 files and directories currently installed.) Removing nodejs (14.14.0-deb-1nodesource1) . dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/gentle-fs' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/cliui/node_modules/strip-ansi' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/cliui/node_modules/ansi-regex' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_modules/cliui/node_modules/string-width' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/cliui/node_modules/is-fullwidth-code-point' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/require-main-filename' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/minimist' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/libnpx' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/configstore' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/get-caller-file' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/wrap-ansi/node_modules/strip-ansi' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/wrap-ansi/node_modules/ansi-regex' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/wrap-ansi/node_modules/string-width' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/wrap-ansi/node_modules/is-fullwidth-code-point' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/dot-prop' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/bin-links' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/strip-ansi' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/ansi-regex' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/locate-path' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/p-try' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/p-locate' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/find-up' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/string-width' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/is-fullwidth-code-point' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs/node_modules/p-limit' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/meant' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/yargs-parser/node_modules/camelcase' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/npm-registry-fetch' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/emoji-regex' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/npm-lifecycle' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/npm-audit-report' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/node_ modules/libcipm' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/docs' not empty so not removed dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules/npm/lib' not empty so not removed Processing triggers for man-db (2.9.1-1) .
NodeJs удалилась. NPM также удалилась (сужу по результату команд: which nodejs which npm)
При этом осталась директория с файликами:
ls /usr/lib/node_modules/npm CHANGELOG.md changelogs CONTRIBUTING.md docs lib LICENSE node_modules npmrc README.md
Вопрос: Как правильно делать удаление (и/или апгрейд на новую версию) NodeJS ?
Спасибо!
- Вопрос задан более трёх лет назад
- 3063 просмотра
How to remove nodejs from Ubuntu 16.04?
I want to uninstall nodejs and npm and have seen several posts which suggest this is the most common way:
sudo apt-get purge --auto-remove nodejs
However, this produces a prompt which seems to reference dependencies which, if they were removed, sound like they would cause problems. What is the best way to «undo» the install of nodejs and npm ?
Reading package lists. Done Building dependency tree Reading state information. Done The following packages will be REMOVED: gyp* libboost-python1.58.0* libjs-inherits* libjs-node-uuid* libjs-underscore* libssl-dev* libssl-doc* libuv1* libuv1-dev* linux-headers-4.4.0-18* linux-headers-4.4.0-18-generic* linux-headers-4.4.0-21* linux-headers-4.4.0-21-generic* linux-image-4.4.0-18-generic* linux-image-4.4.0-21-generic* linux-image-extra-4.4.0-18-generic* linux-image-extra-4.4.0-21-generic* linux-signed-image-4.4.0-18-generic* linux-signed-image-4.4.0-21-generic* node-abbrev* node-ansi* node-ansi-color-table* node-archy* node-async* node-block-stream* node-combined-stream* node-cookie-jar* node-delayed-stream* node-forever-agent* node-form-data* node-fstream* node-fstream-ignore* node-github-url-from-git* node-glob* node-graceful-fs* node-gyp* node-inherits* node-ini* node-json-stringify-safe* node-lockfile* node-lru-cache* node-mime* node-minimatch* node-mkdirp* node-mute-stream* node-node-uuid* node-nopt* node-normalize-package-data* node-npmlog* node-once* node-osenv* node-qs* node-read* node-read-package-json* node-request* node-retry* node-rimraf* node-semver* node-sha* node-sigmund* node-slide* node-tar* node-tunnel-agent* node-underscore* node-which* nodejs* nodejs-dev* npm* python-configobj* python-pycurl* python-pyexiv2* python-pyexiv2-doc* 0 to upgrade, 0 to newly install, 72 to remove and 0 not to upgrade. After this operation, 631 MB disk space will be freed. Do you want to continue? [Y/n]
Edit: This is the output from sudo apt-get purge nodejs :
Reading package lists. Done Building dependency tree Reading state information. Done The following packages were automatically installed and are no longer required: gyp libboost-python1.58.0 libjs-inherits libjs-node-uuid libjs-underscore libssl-dev libssl-doc libuv1 libuv1-dev linux-headers-4.4.0-18 linux-headers-4.4.0-18-generic linux-headers-4.4.0-21 linux-headers-4.4.0-21-generic linux-image-4.4.0-18-generic linux-image-4.4.0-21-generic linux-image-extra-4.4.0-18-generic linux-image-extra-4.4.0-21-generic linux-signed-image-4.4.0-18-generic linux-signed-image-4.4.0-21-generic python-configobj python-pycurl python-pyexiv2 python-pyexiv2-doc Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: node-abbrev* node-ansi* node-ansi-color-table* node-archy* node-async* node-block-stream* node-combined-stream* node-cookie-jar* node-delayed-stream* node-forever-agent* node-form-data* node-fstream* node-fstream-ignore* node-github-url-from-git* node-glob* node-graceful-fs* node-gyp* node-inherits* node-ini* node-json-stringify-safe* node-lockfile* node-lru-cache* node-mime* node-minimatch* node-mkdirp* node-mute-stream* node-node-uuid* node-nopt* node-normalize-package-data* node-npmlog* node-once* node-osenv* node-qs* node-read* node-read-package-json* node-request* node-retry* node-rimraf* node-semver* node-sha* node-sigmund* node-slide* node-tar* node-tunnel-agent* node-underscore* node-which* nodejs* nodejs-dev* npm* 0 to upgrade, 0 to newly install, 49 to remove and 0 not to upgrade. After this operation, 27.6 MB disk space will be freed. Do you want to continue? [Y/n]
How to uninstall Node.js? Remove Node.js from your system completely
There is no restriction on the type of programming language used for writing server-side code. Some of the popular examples include PHP, Ruby, C#, Python, and Javascript. Out of all these, Javascript is very much popular because of its beginner-friendliness and being able to be used both on the client-side and server-side as well.
As the server-side runtime environment for Javascript, Node.js lets you build scalable web applications with ease. Despite its popularity among beginning developers, Node.js does not fit every developer’s needs, especially those with different language backgrounds or preferences.
This tutorial will walk you through a step-by-step guide to completely remove Node.js from your computer. Let’s take a deep breath and dive right in!
Prerequisites
Before uninstalling Node.js, it is important that we check if Node.js is properly installed in our system or not. The way we can check that varies by the operating system.
Check if Node.js installed on Windows
- Using File Explorer:
- Go to File Explorer, open This PC ->C:/ drive.
- Look for the Nodejs folder in the directory where you installed Nodejs originally.
- Some of the other files where we can check for Nodejs or npm files:
- C:Program Files (x86)Nodejs
- C:Program FilesNodejs
- C:Users»user»AppDataRoamingnpm
- C:Users»user»AppDataRoamingnpm-cache
Using CMD:
- Search for “ cmd ” in the start menu. Right-click on it and select “Run as administrator”.
- Or, Press Win+R to open “run”. Enter “ cmd ” and hit Ctrl+Shift+Enter to open the command prompt as administrator.
- Write the following command:
Code language: JavaScript (javascript)node --versionIf you get a result like this, it indicates Node is correctly installed on your system:
Code language: JavaScript (javascript)v16.16.0Check if Node.js installed on Linux
You can check if Node.js is installed by typing node -v in Terminal. The version number will appear in the terminal. It should look something like this:
Code language: JavaScript (javascript)v16.16.0Check if Node.js installed on Mac
- Press command+space to open Spotlight Search.
- Type “ Terminal ” and press enter.
- Check if Node.js is installed by typing node -v in Terminal.
- You should see the version of Node.js that was installed, something like this:
Code language: JavaScript (javascript)v16.16.0Uninstalling the Node.js in Windows
There are actually three ways through which we can remove Node.js from our windows system. Let’s have a look at each of them.
Method 1: Uninstalling from Windows Settings
- Go to Settings by searching it in the start menu.
- Click on the Apps section.
- Look for the search box under Apps & Features section, and enter Nodejs there.
- Select on Nodejs application and click on uninstall.
- It is recommended that you restart your Windows machine even if you aren’t prompted to do so.
- Lastly, run cmd as administrator and type:
Code language: JavaScript (javascript)node --version
- If you see an output like this: then Node is successfully uninstalled from your computer.
Method 2: Uninstalling from Windows CMD
- Search for “ cmd ” in the start menu. Right-click on it and select “Run as administrator“.
- Or, Press Win+R to open “run“. Enter “ cmd ” and hit Ctrl+Shift+Enter to open the command prompt as administrator.
- Run the following command in your terminal to clear your npm cache:
Code language: JavaScript (javascript)npm cache clean --force- Now, to remove Node.js and npm successfully:
- Go to the windows control panel.
- Select Uninstall a program.
- Right-Click on Nodejs and uninstall.
- Lastly, run cmd as administrator and type:
Code language: JavaScript (javascript)node --version
- If you see an output like this: then Node is successfully uninstalled from your computer.
Method 3: Uninstalling from Windows Registry
- Search for “ Registry Editor ” in the start menu and click on it.
- Or, Press Win+R to open “run“. Enter “ regedit ” and hit Enter to open the Windows Registry.
- A prompt will open asking you to allow the app to make changes. Click Yes.
- You can either go to the path below or paste it in the path field: ComputerHKEY_LOCAL_MACHINESOFTWARENode.js
- As a next step, locate the Nodejs directory on the left sidebar. Right-click on it and delete the directory.
- It is recommended that you restart your Windows machine even if you aren’t prompted to do so.
- Lastly, run cmd as administrator and type:
Code language: JavaScript (javascript)node --version
- If you see an output like this: then Node is successfully uninstalled from your compute
Uninstalling the Node.js in Ubuntu
We will examine multiple options to uninstall NodeJS in Ubuntu using the three typical commands: uninstall, remove and purge.
Step 1: Locating the Binary Files
You can locate the folder where NodeJS binaries are located and verify if it’s uninstalled as well. This can be done using the which or find command as shown below:
Code language: JavaScript (javascript)$ which node $ find $(echo $PATH | sed 's/:/ /g') -name "node"Code language: JavaScript (javascript)$ find / -name "node"You should see an output similar to this if the node is installed:
Code language: JavaScript (javascript)/user/bin/node /user/bin/nodeCode language: JavaScript (javascript)/user/bin/node /user/share/doc/node /user/share/code/resources/app/extensions/emmet/dist/node /user/share/code/resources/app/extensions/css-language-features/server/dist/node /user/share/code/resources/app/extensions/css-language-features/client/dist/node /user/share/code/resources/app/extensions/ms-vscode.js-debug/src/targets/node /user/share/code/resources/app/extensions/html-language-features/server/dist/node /user/share/code/resources/app/extensions/html-language-features/client/dist/node /user/share/code/resources/app/extensions/json-language-features/server/dist/node /user/share/code/resources/app/extensions/json-language-features/client/dist/node /user/share/code/resources/app/out/vs/workbench/api/node /user/share/code/resources/app/out/vs/workbench/contrib/debug/node /user/share/code/resources/app/out/vs/workbench/contrib/externalTerminal/node /user/share/code/resources/app/out/vs/base/node /user/share/code/resources/app/out/vs/platform/files/node /user/share/code/resources/app/out/vs/platform/environment/node /user/share/code/resources/app/out/vs/platform/terminal/node j/user/share/code/resources/app/out/vs/code/node /user/include/nodeStep 2: Uninstalling NodeJS
Now, there are different ways of removing Nodejs from the system. Let’s look at some of the options below:
Method 1: Removing the binary paths
We can discard Nodejs by manually deleting the binaries we located in the previous step, although this method is less recommended than others.
Code language: JavaScript (javascript)$ sudo rm /user/bin/nodeMethod 2: Use the apt or apt-get command to Uninstall
The most commonly used commands in Ubuntu to uninstall NodeJS are apt and apt-get.
Code language: JavaScript (javascript)$ sudo apt-get remove nodejsThe above command only removes the package. In order to remove all the node-related packages as well, see the methods in step 4.
Method 3: Uninstalling a Particular version of NodeJS
Suppose you want to uninstall only a specific version of NodeJS. You can use the below command to remove that version only. Eg:
Code language: JavaScript (javascript)$ nvm uninstall 16.16.0You should see an output like this:
Code language: JavaScript (javascript)Uninstalled node v16.16.0Step 3: Removing NodeJS info from the Source Lists
After removing NodeJS, check to see if there is any NodeJS data present in the /etc/apt/sources.list.d directory:
Code language: JavaScript (javascript)$ ls /etc/apt/sources.list.dYou should see folders named nodesource.list and nodesource.list.distUpgrade. If not present then your NodeJS information is removed from the sources list. Otherwise, Use the below command to remove them:
Code language: JavaScript (javascript)$ rm -rf nodesource.list nodesource.list.distUpgradeLast but not the least, make sure to update the Ubuntu repositories.
Code language: JavaScript (javascript)$ sudo apt-get updateStep 4: Clearing the Cache
NodeJS can sometimes leave traces of some packages and modules after uninstalling. You can use any of the following methods to remove all the node-related packages as well as the configuration files.
Method 1: Using the purge command
The purge command helps us remove all these packages and files. Use any of the two commands below:
Code language: JavaScript (javascript)$ sudo apt-get purge nodejsCode language: JavaScript (javascript)$ sudo apt-get purge – auto-remove nodejsMethod 2: Removing npm manually
You can manually remove the hidden npm directories and other related files using the below commands:
Code language: JavaScript (javascript)$ ls -la $ rm -rf .npmStep 5: Remove Unused Files
The last step is to run the following command to get rid of unused files and free up the space on your computer.
Code language: JavaScript (javascript)$ sudo apt-get autoremoveUninstalling the Node.js on Mac
Now, let’s look at some of the ways to uninstall Node.js from MacOS as well.
Method 1: Uninstalling using homebrew
- Click on the search icon in the menu bar or press command + space to launch the spotlight.
- Type terminal and hit Return .
- Run this command to uninstall all versions of Node from your mac.
Code language: JavaScript (javascript)# brew uninstall --force node- Once that’s done, type the following command to remove unused folders and dependencies.
Code language: JavaScript (javascript)# brew cleanupMethod 2: Uninstalling using NVM
- Click on the search icon in the menu bar or press command + space to launch the spotlight.
- Type terminal and hit Return .
- To uninstall the node with the help of nvm, type the following command, replacing with the current version of your node installed. Eg: v16.16.0.
# nvm uninstallCode language: JavaScript (javascript)Method 3: Uninstalling using terminal
- Click on the search icon in the menu bar or press command + space to launch the spotlight.
- Type terminal and hit Return .
- Once the terminal is opened, enter the given below command:
Code language: JavaScript (javascript)# sudo rm -rf /usr/local/,bin,share/man>/- The above command will not remove all of the packages. To delete every global package you have installed using npm, run the below command:
Code language: JavaScript (javascript)# rm –rf ~/.npmMethod 4: Uninstalling Node Manually
- From the Dock, select the Go menu and then Folder from the Finder icon.
- In the text box, paste the directory path: /usr/local/lib
- Then move any files that have the name ‘node’ to the Trash.
- Paste each of the following paths into the text box in Go to Folder and drag the files with the name ‘node’ to the Trash.
Code language: JavaScript (javascript)/usr/local/bin /usr/local/include /usr/local/share/man/man1/ /usr/local/lib/dtrace/ /opt/local/bin/ /opt/local/include/ /opt/local/include/ /usr/local/share/doc/ /usr/local/share/systemtap/tapset/- Drag the following files in the Home folder to the Trash: .npm, .node-gyp, .nodereplhistory .
- Lastly, empty the Trash.
Conclusion
That was pretty much it! Hopefully, you can now successfully uninstall NodeJS from your computer.
If you ever feel lost and want help understanding where to start your coding journey then go check out Codedamn. There are amazing courses and blogs for web development and other coding concepts. Remember to practice coding on a daily basis. You can play around with your code on Codedamn’s online compiler as well
Let us know in the comments if you have any suggestions or queries. Finally, If you are interested in my content and would like to connect, then you can find me on Linkedin or Twitter.
Become The Best Full-Stack Developer
Codedamn is the best place to become a proficient developer. Get access to hunderes of practice Node.js courses, labs, and become employable full-stack web developer.
Unlimited access to all platform courses
100+ practice projects included
ChatGPT Based Instant AI Help
Structured Node.js Full-Stack Roadmap To Get A Job
Exclusive community for events, workshops
Sharing is caring
Did you like what Indrakant wrote? Thank them for their work by sharing it on social media.
How to Install/Uninstall NodeJS on Ubuntu 18.04

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
NodeJS is a JavaScript framework that allows you to build fast network applications with ease. In this guide, we delve in and see how you can How to install NodeJS on Ubuntu 18.04.
Step 1: Adding the NodeJS PPA to Ubuntu 18.04
To start off, add the NodeJS PPA to your system using the following commands.
sudo apt-get install software-properties-common
Sample Output Next, add the NodeJS PPA.
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
Sample Output Great! In our next step, we are going to run the command for installing NodeJS.
Step 2: Install NodeJS on Ubuntu
After successfully adding the NodeJS PPA, It’s time now to install NodeJS using the command below.
sudo apt-get install nodejs
Sample Output This command not only installs NodeJS but also NPM (NodeJS Package Manager) and other dependencies as well.
Step 3: Verfiying the version of NodeJS and NPM
After successful installation of NodeJS, you can test the version of NodeJS using the simple command below.
node -v
Sample Output For NPM, run
npm -v
Sample Output
Step 4: Creating a Web Server demonstration
This is an optional step that you can use to test if NodeJS is working as intended. We are going to create a web server that displays the text “Congratulations! node.JS has successfully been installed !” Let’s create a NodeJS file and call it nodeapp.js
vim nodeapp.jsAdd the following content
var http = require('http'); http.createServer(function (req, res) < res.writeHead(200, ); res.end('Congratulations! node.JS has successfully been installed !\n'); >).listen(3000, " server-ip); console.log('Server running at https://server-ip:3000/');Save and exit the text editor Start the application using the command below
node nodeapp.js
Sample Output This will display the content of the application on port 3000. Ensure the port is allowed on the firewall of your system.
ufw allow 3000/tcp ufw reloadNow open your browser and browse the server’s address as shown
https://server-ip:3000
Uninstall NodeJS from Ubuntu
If you wish to uninstall NodeJS from your Ubuntu system, run the command below.
sudo apt-get remove nodejsThe command will remove the package but retain the configuration files. To remove both the package and the configuration files run:
sudo apt-get purge nodejsAs a final step, you can run the command below to remove any unused files and free up the disk space
sudo apt-get autoremoveGreat! We have successfully installed and tested the installation of NodeJS. We also learned how to uninstall NodeJS from Ubuntu and clean up space.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases. Learn more about us
