How can I delete NodeJS in ubuntu 20.4? - node.js

I've tried various ways to clear this version of Node.js. But in the end, this version is not deleted!
I tried several methods like this

Run the following commands in your terminal.
sudo apt-get remove nodejs
sudo apt-get purge nodejs
sudo apt-get autoremove

You have to try the following steps
npm cache clean -f
npm install -g n
sudo n [version]
the version that you want

For some reason or another node was installed twice on my Ubuntu 20:
/usr/bin/node # Installed by apt
/usr/bin/nodejs -> /usr/bin/node
/usr/local/bin/node # Nightly
I solved the problem by:
sudo rm /usr/local/bin/node && sudo ln -s /usr/bin/node /usr/local/bin/node
Resulting in
/usr/bin/node # Installed by apt
/usr/bin/nodejs -> /usr/bin/node
/usr/local/bin/node -> /usr/bin/node
Solved my troubles with gulp-sass.

Related

npm issue on EC2 instance

I download and compiled node and npm on EC2 instance. Everything seems right (the -v are shown on both), but when I try to npm install pm2 ask for me to run the command as Root (I am), yet when I sudo npm install says sudo: npm: command not found. Any ideas? Thanks.
This solved the issue.
sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm

Empty output with forever for nodejs

I have a nodeJS server that I want to run forever.
I found this package https://github.com/foreverjs/forever
I installed it using this command line sudo npm install forever -g
But when I test it, there is no output (even not for help).
What it can be?
If you installed on Ubuntu through apt package manager you need to create a symbolic link since npm modules try to run via /usr/bin/node
sudo ln -s `which nodejs` /usr/bin/node
or automatically via apt
sudo apt-get install nodejs-legacy

Cannot install NodeJs: /usr/bin/env: node: No such file or directory

I'm trying to install nodeJs into my Ubuntu 14.04 in order to use GruntJs.
I've read about Ubuntu different way of doing it (issues?), so this is what I've done in order to install it:
sudo apt-get install npm
sudo npm install -g grunt-cli
Typing grunt after that I've got the error:
/usr/bin/env: node: No such file or directory
So, I've tried:
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
sudo apt-get update
And trying again, and still getting the error, I've tried:
sudo add-apt-repository https://launchpad.net/~chris-lea/+archive/node.js/
sudo apt-get install -y nodejs
I've got this message:
nodejs is already the newest version.
0 to upgrade, 0 to newly install, 0 to remove and 3 not to upgrade.
I did try a cleanup just in case:
sudo apt-get autoremove
But nope, the error is still there: when I type grunt I still get /usr/bin/env: node: No such file or directory
What should I do?
Doing a symlink solves the issue:
ln -s /usr/bin/nodejs /usr/bin/node
(My thanks and +1 vote to bodokaiser's answer).
The issue is not with the version of node. Instead, it is the way NodeJS is installed by default in Ubuntu. When running a Node application in Ubuntu you have to run nodejs somethign.js instead of node something.js
So the application name called in the terminal is nodejs and not node. This is why there is a need for a symlink to simply forward all the commands received as node to nodejs.
sudo ln -s /usr/bin/nodejs /usr/bin/node
if you are using nvm node version manager, use this command to create a symlink:
sudo ln -s "$(which node)" /usr/bin/node
sudo ln -s "$(which npm)" /usr/bin/npm
The first command creates a symlink for node
The second command creates a symlink for npm
I think you should upgrade lastest node version
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
if you are able to access node on ubuntu terminal using nodejs command,then this problem can be simply solved using
-creating a symbolic link of nodejs and node using
ln -s /usr/bin/nodejs /usr/bin/node
and this may solve the problem
In my case, installing nodejs-legacy solved the issue.
sudo apt-get install nodejs-legacy
Just do
$ sudo apt-get install nodejs-legacy
And it will start working.
If you already have nodejs installed (check with which nodejs) and don't want to install another package, you can, as root:
update-alternatives --install /usr/bin/node node /usr/bin/nodejs 99
I've found this is often a misnaming error, if you install from a package manager you bin may be called nodejs so you just need to symlink it like so
ln -s /usr/bin/nodejs /usr/bin/node
Depending on how you installed your node, most of the time it might not be in /usr/bin/, in my own case it was I used nvm to install so my node was in ./nvm/versions.
Using this command which node I found out the path, but to make the work easier you can run this command.
nodepath=$(which node); sudo ln -s $nodepath /usr/bin/node
the above command will get the location of your node and create a link for you.
When I was using gulp i got this error.
~$ gulp
/usr/bin/env: ‘node’: No such file or directory
This was removed by executing following command you have to keep in mind that /usr/bin directory has all permissions.
~$ ln -s /usr/bin/nodejs /usr/bin/node
this works for me..
Follow these commands to fix the problem.
In a terminal:
Clean the entire NPM cache:
$ sudo npm cache clean -f
sudo npm install -g n
Install the latest stable version of Node.js:
sudo n stable
Now the latest version of Node.js was installed. Check the version using:
node -v
There are two solutions to this:
a) Set your PATH variable to include "/usr/local/bin"
export PATH="$PATH:/usr/local/bin"
b) Create a symlink to "/usr/bin" which is already in your PATH
ln -s /usr/bin/nodejs /usr/bin/node
I hope it helps.
While ln -s is the obvious easiest fix, a piece of explanation:
Because of a conflict with another package, the executable from the
Ubuntu repositories is called nodejs instead of node. Keep this in
mind as you are running software.
This advice comes up, when installing sudo apt-get install nodejs.
So some other known tool (I don't know what it does. While being known to ubuntu repositories, it is not installed by default in 16.04) occupies that namespace.
Would have been nice, if Ubuntu had offered an advice how to fix this 'cleanly', if not by doing by hand what otherwise the package would do. (a collision remains a collision... if+when it would occur)
In case it's installed by using snap,
sudo ln -sfn /snap/node/current/bin/node /usr/bin/node
sudo PATH="$PATH:/usr/local/bin" npm install -g <package-name>
For my case link did NOT work as follow
ln -s /usr/bin/nodejs /usr/bin/node
But you can open /usr/local/bin/lessc as root, and change the first line from node to nodejs.
-#!/usr/bin/env node
+#!/usr/bin/env nodejs
Just rename the command or file name ln -s /usr/bin/nodejs /usr/bin/node by this command
For me the accepted answer did not yet work. I started off as suggested here:
ln -s /usr/bin/nodejs /usr/bin/node
After doing this I was getting the following error:
/usr/local/lib/node_modules/npm/bin/npm-cli.js:85
let notifier = require('update-notifier')({pkg})
^^^
SyntaxError: Block-scoped declarations (let, const, function, class)
not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
The solution was to download the most recent version of node from https://nodejs.org/en/download/ .
Then I did:
sudo tar -xf node-v10.15.0-linux-x64.tar.xz --directory /usr/local --strip-components 1
Now the update was finally successful: npm -v changed from 3.2.1 to 6.4.1
sudo nautilus
Open file manager as admin. Go to /usr/bin and search node.That might have been broken link, so delete it. No try installing your package.
It might work -worked for me
it's been 7 years ago and the problems still relevant and occurred.
Oke here my problem, it's similar but not exactly the same.
When I call this command from Jenkins
ssh root#xxx.xxx.xxx.xxx "pm2 restart app"
then error /usr/bin/env Node No Such file or directory
Then here my solution:
on server xxx.xxx.xxx.xxx
It relink /usr/bin/node
First:
I remove the existing one with command "rm -f /usr/bin/node"
Second:
I create new link with this command
"ln -s /root/.nvm/versions/node/v14.17.4/bin/node /usr/bin/node"
Node version it's depends on your installation. May it help.
THe bottom line for this error is link of node.
For those who have installed NodeJS with nvm.
If like me you have installed, uninstalled, reinstalled some versions you simply need to do this :
nvm use v14.21.1
Or whatever version you are using.
This will recreate the links to node and npm commands that where lost during your 'cleanup' :D

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

On EC2: sudo node command not found, but node without sudo is ok

I have just installed nodejs on a new EC2 micro instance.
I installed it normally, ./configure -> make -> sudo make install.
Problem: When I run "node" under ec2-user, it runs perfectly. When I run "sudo node", it fails.
I found out that node is in:
[ec2-user#XXXX ~]$ whereis node
node: /usr/local/bin/node /usr/local/lib/node
and the current path is
[ec2-user#XXXX ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/opt/aws/bin:/home/ec2-user/bin
but, the sudo path is
[root#ip-10-112-222-32 ~]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin
then I tried to edit the root PATH to include the paths to node, so "node" runs when I'm logged in as root - but it still won't work when I log in as ec2-user and run "sudo node".
I need this to install npm properfly. Any idea on how to include the node path while running "sudo node"?
Yes, it is a bit annoying but you can fix it with some links:
sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
There might be more but that is all I have run across so far. Lack of node-waf will cause some npm installs to fail with a rather cryptic error message.
I added /usr/local/bin to secure_path in /etc/sudoers
$ sudo visudo
Then change this line:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
To:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
it happens because the node executable is not found in /usr/bin. So follow the steps:
find node:
whereis node
in my case: node: /home/<my_user>/.nvm/versions/node/v8.9.4/bin/node
make a symbolic link for node:
sudo ln -s /home/<my_user>/.nvm/versions/node/v8.9.4/bin/node /usr/bin/node
It's done!
Why not use the absolute path to node? If you planning to use an upstart script it is going to need an absolute path anyways.
sudo /usr/local/bin/node server.js
try the following:
export PATH=$PATH:/usr/local/bin
sudo node --version
You could pass full path to node executable from parent (non-sudo shell) using which command.
sudo `which node`
For me, it worked to just change ownership of node folder from root to ec2-user (logged in as ec2-user).
(Note: I created my node folder in /var/lib/)
sudo chown -R ec2-user /var/lib/node/
Then
npm install mongojs
should work fine (provided you have installed npm ok of course!)
How about using "sudo $(which node)" instead of "sudo node" ?
Here's an approach that doesn't use symlinks, or require root:
$ git clone https://github.com/joyent/node.git
$ cd node
$ mkdir ~/opt
$ export PREFIX=~/opt; ./configure
$ make
$ make install
$ echo 'export PATH=~/opt/bin:${PATH}' >> ~/.bashrc
Then I did:
$ git clone https://github.com/isaacs/npm.git
$ cd npm
$ make install
The benefits of not running node as root are discussed here:
http://increaseyourgeek.wordpress.com/2010/08/18/install-node-js-without-using-sudo/
Its inline with:
https://github.com/joyent/node/wiki/Installation
In my case, Node was installed without sudo prefix. So node was unavailable for the superuser that why it is not working sudo node server
Enter as root with
sudo su
and then do standard steps
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
node -e "console.log('Running Node.js ' + process.version)"
This is what I did to solve a similar issue. Note: I had installed node via snap.
Step 1: Install node via snap
sudo snap install node --classic
Step 2: Find where node has been installed
whereis node
In my case
/snap/bin/node.npm
/snap/bin/node.npx
/snap/bin/node.yarn
/snap/bin/node
/snap/bin/node.yarnpkg
Step 3: Create symbolic links to node, npm, npx and yarn
sudo ln -s /snap/bin/yarn /usr/bin/yarn
sudo ln -s /snap/bin/node /usr/bin/node
sudo ln -s /snap/bin/npm /usr/bin/npm
Finally node is accessible for all users, even sudo group
sudo node
I tried everything mentioned in the above answers but nothing worked. Probably because of my lack of understanding of concepts related to sym links. I fixed the issue by not using nvm.
I just created a new ec2 instance and didn't install nvm. Instead I installed node and npm like so:
sudo apt update
sudo apt install nodejs npm
And this did it for me.
If you have installed node environment already, paste these command in you r instance and it'll link your node to your user directory. And you will be able to use node with sudo.
sudo ln -s "$(which node)" "/usr/local/bin/node"
sudo ln -s "$(which npm)" "/usr/local/bin/npm"
I don't know if this is the right way, but this is what i did...
sudo su
export PATH=$PATH:/home/ec2-user/local/node/bin
curl http://npmjs.org/install.sh | sh
chown -R ec2-user /home/ec2-user/local/node
exit
This installed npm, and I can now install any packages I want.

Resources