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.

Answer from Raja on Stack Overflow
🌐
GitHub
github.com › nodejs › help › issues › 3605
How to Uninstall older version of Node JS installed in Ubuntu · Issue #3605 · nodejs/help
August 28, 2021 - Details How to uninstall remove older version of node js and install newer version. Need some help regarding this. Node.js version 10.19.0 Example code No response Operating system Ubuntu / LInux Scope Not applicable Module and version N...
Published   Nov 12, 2021
🌐
Groove Technology
groovetechnology.com › home › blog › technologies › how to remove nodejs from ubuntu? a comprehensive guide
A Complete Guide To Removing NodeJS From Ubuntu
September 26, 2024 - If NodeJS was installed using the apt-get package manager, you can remove it using the following command: ... Replace with the version of NodeJS you want to uninstall.
🌐
Stack Overflow
stackoverflow.com › questions › 57200118 › how-to-remove-the-old-version-of-node-js › 57201049
node.js - How to remove the old version of node js? - Stack Overflow
I have a version of node JS as 8.10.0 on Linux mint. But I want to install the latest stable version 10.16.0. For upgrade node js version I have followed the following steps: sudo npm cache ...
Top answer
1 of 5
137

As seen from the output of:

sudo apt-get purge nodejs

it is only removing node related packages i.e. relevant packages, nothing more.

On the other hand, when you do:

sudo apt-get purge --auto-remove nodejs

it is essentially doing:

sudo apt-get purge nodejs
sudo apt-get autoremove

and the removal of the gyp, linux-headers-4.4.0-18-generic etc packages are actually triggered by autoremove as they were installed as dependencies and no longer needed by any installed package, presumably because the main package has been removed.

So it is perfectly fine in this context to run:

sudo apt-get purge --auto-remove nodejs

If you are too paranoid, you can do it in two steps: first purge nodejs:

sudo apt-get purge nodejs

and then remove the orphan dependencies (till now, if any):

sudo apt-get autoremove
2 of 5
26

To remove node js, npm and node_modules from Ubuntu, you need to remove containers also which are at different locations in Ubuntu. These could be as:

/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

I have posted the procedure to remove NodeJS on my blog: AMCOS IT Support For Windows and Linux: To completely uninstall node js from Ubuntu.

  1. First of all you need to run the following command from command terminal as sudo.

    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
    
  2. Remove node or node_modules directories from /usr/local/lib with the help of following command.

    sudo rm -rf /usr/local/lib/node*
    
  3. Remove node or node_modules directories from /usr/local/include with the help of following command.

    sudo rm -rf /usr/local/include/node*
    
  4. Remove any node file or dir from /usr/local/bin with the help of following command.

    sudo rm -rf /usr/local/bin/node*
    
  5. Go to home directory and remove any node or node_modules directory, if exists.

🌐
DigitalOcean
digitalocean.com › community › tutorials › install-uninstall-nodejs-ubuntu
How to Install/Uninstall NodeJS on Ubuntu 18.04 | DigitalOcean
August 3, 2022 - As a final step, you can run the command below to remove any unused files and free up the disk space ... Great! We have successfully installed and tested the installation of NodeJS. We also learned how to uninstall NodeJS from Ubuntu and clean up space.
Top answer
1 of 2
5

4.2.6 is indeed the version of Node that is in the Xenial repos. Ubuntu does not do major version updates of packages within the same distribution, so if Node 4 was what was around when Xenial came out (which is to say, April of 2016, which sounds about right -- it would have been the then-current LTS release), then you're stuck with version 4 all the way through Xenial's lifetime until you upgrade the distro.

At least, that's the case when using the official repositories. Fortunately, a more up-to-date repository for Node does exist and is recommended on Node's official site. You can find detailed instructions here, but the tl;dr is:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
2 of 2
0

Ubuntu has this version of nodejs because it was one of the LTS versions (long term support) and is very stable.

There are a few different ways to install newer versions. I would recommend installing it through nvm so you get access to the latest versions. Plus it helps to do it this way if you will be developing on multiple systems rather than leaving it up to the systems package manager. To do this first remove the current version

sudo apt-get remove nodejs

To ensure it's completely removed you can do sudo apt-get purge nodejs and sudo apt-get autoremove

Now we can prepare to use npm by installing build-essential and libssl-dev

sudo apt-get install build-essential libssl-dev

Now we can download the nvm installation script from the projects Github page

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh

Run the install script with

bash install_nvm.sh

At this point it is easiest to logout, and then log back in to complete the setup of npm.

Now we can use the following commands to install the target nodejs version

nvm ls-remote shows you the available versions

nvm install (versionNumber)

nvm use (versionNumber) You can have multiple versions installed so you can choose which one to use

then verify the version you have chosen to use with

node -v <- Please note that with npm the command is node and NOT nodejs

There is a great write up about all of this on Digital Ocean. For more information visit the link https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04

Find elsewhere
🌐
AlmaBetter
almabetter.com › bytes › articles › uninstall-node-js-ubuntu
How to Uninstall Node JS in Ubuntu? (Step by Step Guide)
October 17, 2023 - Take note of these versions as you may need them for future reference when reinstalling Node.js. Check out the Node JS tutorial! How to uninstall node in Ubuntu - it relies on the APT (Advanced Package Tool) package manager for handling software installations. To uninstall Node js Ubuntu, you'll start by removing ...
🌐
Codedamn
codedamn.com › news › node.js
How to uninstall Node.js? Remove Node.js from your system completely
June 2, 2023 - The most commonly used commands in Ubuntu to uninstall NodeJS are apt and apt-get. $ sudo apt-get remove nodejsCode language: JavaScript (javascript) The above command only removes the package.
Top answer
1 of 2
4

I had problems with this as well. So there are many tutorials how to install different version of nodejs but they did not work in my case. However the last with nvm did.

Method 1: Install nodejs from specific source

cd ~
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh

by changing setup_16.x to your version, you change the version

sudo bash nodesource_setup.sh

then you test sources with

# sample on Ubuntu 22.10
$ cat /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_16.x focal main
deb-src https://deb.nodesource.com/node_16.x focal main

Then you install nodejs from that source (did not work in my case)

sudo apt -y install nodejs

And check installed version

node -v

This should return

v16.19.0

but in my case (Ubuntu 22.10) I got the new version

v18.7.0

Method 2: Install Node Vesrion Manager or nvm This worked in my case:

sudo apt install curl 
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash 
source ~/.bashrc 

Now to install an older version of nodejs with nvm

you can first check available versions by

nvm list-remote

and then install specific version by (ex. version v16.19.0)

nvm install 16.19.0

and check with:

$ node -v
v16.19.0

To install latest version of node with nvm

nvm install node 

$ node -v
v18.7.0

Hope this helps someone to

2 of 2
0

Install NVM, and the install node using nvm. Here is an example.

  1. Install nvm

     ubuntu@ip-172-26-0-227:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
     % Total    % Received % Xferd  Average Speed   Time    Time     Time  
     Current
                                  Dload  Upload   Total   Spent    Left  
     Speed
     100 16555  100 16555    0     0   198k      0 --:--:-- --:--:-- --:--:--  199k
    
      => Compressing and cleaning up git repository
    
      => Appending nvm source string to /home/ubuntu/.bashrc
      => Appending bash_completion source string to /home/ubuntu/.bashrc
      => 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
    
  2. Source bashrc so nvm can be loaded, or close and re open terminal.

    ubuntu@ip-172-26-0-227:~$ source /home/ubuntu/.bashrc

  3. Now, install node version, passing the version..etc.

    ubuntu@ip-172-26-0-227:~$ nvm install  v12.22.10
    Downloading and installing node v12.22.10...
    Downloading https://nodejs.org/dist/v12.22.10/node-v12.22.10-linux- 
    x64.tar.xz..100.0%
    Computing checksum with sha256sum
    Checksums matched!
    Now using node v12.22.10 (npm v6.14.16)
    Creating default alias: default -> v12.22.10
    
🌐
Linux Hint
linuxhint.com › completely-uninstall-nodejs-npm-and-node-in-ubuntu
How Can I Completely Uninstall Nodejs, NPM and Node in Ubuntu – Linux Hint
The users can confirm the ... and it can be done by removing the packages from Ubuntu system through the “apt purge –autoremove” command, or removing the source directories of Nodejs and NPM from the system using the “rm -rf” command....
🌐
Medium
medium.com › @scriptsar.info › step-by-step-guide-how-to-install-uninstall-node-js-on-linux-cec1b884a063
Step-by-step guide how to install & uninstall Node.js on Linux: | by scriptsar | Medium
October 9, 2023 - Open the “Ubuntu Software” application. In the search bar at the top right, type “node.” · Locate the “Node.js” package in the search results. Click on “Node.js” to view more details.
🌐
Web Hosting Geeks
webhostinggeeks.com › home › ubuntu › how to uninstall node.js and npm on ubuntu
How to Uninstall Node.js and npm on Ubuntu | Linux Tutorials for Beginners
October 17, 2023 - If using nvm, you can list and uninstall specific versions. For manual installations, navigate to the installation directory and remove the desired version. ... Uninstalling Node.js and npm from your Ubuntu system ...
🌐
ByteXD
bytexd.com › how-to-uninstall-nodejs-in-ubuntu
How to Uninstall NodeJS in Ubuntu 22.04 - ByteXD
July 31, 2022 - As a result, you may need to uninstall the package manager when uninstalling NodeJS in Ubuntu. Besides, you could install, run and uninstall NodeJS versions using the Node Version Manager (nvm). ... It deletes the package without tampering with the user data. So, you can reinstall the application and still trace your previous data. Lastly, you should use the purge command to eliminate the package and its data. ... The key takeaway is that uninstall, remove, and purge all discard NodeJS and related programs.
🌐
Softsuave
softsuave.com › home › how to uninstall node js: best practices for a clean uninstall
How to Uninstall Node js: Best Practices for a Clean ...
May 13, 2025 - Step 1: Remove Node.js To uninstall Node.js on Ubuntu, open the terminal and enter: ... This will remove both npm and Node.js from your system. Step 3: Clean Up Residual Files Follow Step 7 from the Windows section.