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.
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.
Uninstall NodeJS from Ubuntu
The command will remove the package but retain the configuration files.
sudo apt-get remove nodejs
sudo apt-get autoremove
To remove both the package and the configuration files run:
sudo apt-get purge nodejs
sudo apt-get autoremove
Install NodeJS on Ubuntu
Adding the NodeJS PPA to Ubuntu
sudo apt-get install software-properties-common
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
After successfully adding the NodeJS PPA, It’s time now to install NodeJS using the command below.
sudo apt-get install nodejs
Verfiying the version of NodeJS and NPM
node -v
npm -v
More Info: http://www.rscoder.com/2020/04/how-do-i-completely-uninstall-nodejs.html
Uninstall NodeJS from Ubuntu
sudo apt-get remove nodejssudo apt-get update
Follow below link to install latest nodeJs in ubuntu
https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/
Ones you installed successfully, then if you want to check node version use below command.
node -v
- Install npm using curl (or wget)
curl http://npmjs.org/install.sh | sh - Install n using npm
npm install -g n - Install the latest version of node using n
n latest
n is a node version manager. It does all the work for you. It installs and switches to the version you specify, or just switches if you already have it installed.
Note: If you're having trouble installing stuff due to permissions, don't use sudo. Enter this command once to set your user account as the owner of the /usr/local/ directory, so that you can just issue normal commands in there without sudo. It's a more sane alternative.
sudo chown -R $USER /usr/local
Do the exact same thing again. The new binary will be copied over the old one.
git clonecreates a copy of git repository node's source code is incd node/changes directory to the one you just created with those files./configurechecks for dependencies and creates a makefilemakeexecutes that makefile, which results in compiling the source code into binary executable(s), libraries and any other outputsls -llists the files in the current directorynoderuns thenodebinary executable you just compiled from source, to ensure the compilation was successfulsudo make installcopies the files you just created from the current directory to their permanent homes, /usr/local/bin and such
The last step overwrites whatever's already there with what you just built.
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
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.
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_modulesRemove node or node_modules directories from /usr/local/lib with the help of following command.
sudo rm -rf /usr/local/lib/node*Remove node or node_modules directories from /usr/local/include with the help of following command.
sudo rm -rf /usr/local/include/node*Remove any node file or dir from /usr/local/bin with the help of following command.
sudo rm -rf /usr/local/bin/node*Go to home directory and remove any node or node_modules directory, if exists.
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
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
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
Install NVM, and the install node using nvm. Here is an example.
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_completionSource bashrc so nvm can be loaded, or close and re open terminal.
ubuntu@ip-172-26-0-227:~$ source /home/ubuntu/.bashrc
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
Could you give it a shot with this script from the npm site?
It should clean up any old installations you have and install the latest version.
To remove all cached versions except the current version
sudo n prune
Check how much all those versions are taking with du -sh /usr/local/n/versions.
Also,
Remove the installed node and npm (does not affect the cached version). This can be useful to revert to the system version of node (if in a different location), or if you no longer wish to use node and npm, or are switching to a different way of managing them.
sudo n uninstall
You can try running apt-get remove nodejs --purge and apt-get remove npm --purge.
If the command continues to run, you can run find / -name npm, check the results, and delete files that you consider necessary.
To manually remove node js, npm and node_modules from Ubuntu, you need to do the following steps.
- 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
- Remove node or node_modules directories from /usr/local/lib with the help of following command.
sudo rm -rf /usr/local/lib/node*
- Remove node or node_modules directories from /usr/local/include with the help of following command.
sudo rm -rf /usr/local/include/node*
- Remove any node file or dir from /usr/local/bin with the help of following command.
sudo rm -rf /usr/local/bin/node*
- Go to home directory and remove any node or node_modules directory, if exists.
Now it is done