nodejs command not found on VPS - node.js

While setting up a Centos7 VPS server via SSH I have the problem that NodeJS command isn't found.
Installing the latest stable version of nodejs using:
curl —silent —location https://rpm.nodesource.com/setup_10.x | sudo bash -
...results in the instruction: Run 'sudo yum install -y nodejs' to install Node.js 10.x and npm
...running the above command it says: nodejs-10.16.3-1nodesource.x86_64 already installed and latest version
But if I then check the installed versions it isn't found:
[root#server ~]# node -v
v10.16.3
[root#server ~]# npm -v
6.9.0
[root#server ~]# nodejs -v
-bash: nodejs: command not found
I've seen several sources usins nodejs -v to check the version but I'm half convinced they're wrong. Although followup tests like nano also fail.
I've tried re-installing several different ways but it results in the same result.

Add an alias to node can solve your problem.

Related

Node versions do not match: node vs. sudo node -v ... WSL2 Ubuntu 22.04.1

As you can see in the image below, I see two different versions of node depending on which command I run.
I need the newer version, but npm sees the old version.
Many times I've removed, purged, reinstalled, etc.
I tried installing nvm as root and setting the node version there, but that didn't help either.
If I use apt install nodejs instead of nvm, it tells me that I already have the newest version, which it believes is 12.22.9.
How do I get npm to recognize the newer version (18.12.1) of node that I installed via nvm?
It is because you have a different version of the Node.js which is installed for the root and that particular user.
First, you need to uninstall Node.js:
sudo apt-get remove nodejs
or
sudo npm rm npm -g
If you have any problem with the above commands, then after running which node command, go to that directory, and run the following commands:
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Do the same thing for the current user if needed.
The default Ubuntu/Debian package manager does not have the latest Node.js, and that's why whenever you try to install Node.js with apt install nodejs it says you have the latest version.
According to the official Node.js documentation, for installing the latest version, you should follow these steps:
Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
P.S: No need to run npm or node with sudo. Therefore, I highly recommend you to not use every command with sudo.

npm show "NPM ELF : not found error" in WSL

i got error when running npm, i've allready try to reinstall with
sudo apt-get remove nodejs npm -y && sudo apt-get install nodejs npm -y
this problem still exist
/usr/bin/node: 1: ELF: not found
/usr/bin/node: 2: : not found
/usr/bin/node: 4: Syntax error: Unterminated quoted string
im using Ubuntu WSL
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
Linux localhost 4.4.0-19041-Microsoft #1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 x86_64 x86_64 GNU/Linux
npm -v command
npm -v
-bash: /usr/bin/node: cannot execute binary file: Exec format error
I could not get the solution to work, which was given here.
A different solution propossed from the same source which itself linked to here worked for me:
I first removed node and npm completly (To be precise all packages with the name in it, but I am not sure this is necessary). Then I used the give install command:
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
This is for Ubuntu and node version 18, but you can find other operating systems and versions as well (look here).
I hope this helps someone.
This was an issue for me on Windows 10, using WSL2 and Ubuntu 22.04 LTS. The other solutions in this post did not help, and I was unwilling to downgrade to Ubuntu 20. Instead, I managed to fix it by removing all node-related packages with apt and then installing node via nvm as per this guide by Microsoft.
So to remove the packages:
sudo apt-get remove --purge nodejs npm
Then install nvm...
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Restart the terminal. Then, make sure nvm is installed:
nvm --version
Finally, use nvm to install the latest version of node and npm:
nvm install node
Check to make sure node and npm are installed:
node --version
npm --version
Hope this helps!
i found same problem in github
https://github.com/microsoft/WSL/issues/8151
then i fix this problem with
wget https://gist.githubusercontent.com/lexavey/155a95d803224d7c0af7e225d0d82396/raw/3b4c103e4c3ff702674f96dd12cc412e9c8766ad/fixexec.py
sudo python3 ./fixexec.py $(realpath $(command -v node))
node -v
hope help other with same problem
Seems like an issue with WSL Ubuntu 22 Jammy and 8.5.1 package.
You may have luck installing a different package version, but I had issues with this.
Installed WSL Ubuntu 20 with 6.14.4, issue was gone.

How to install node.js and npm on Ubuntu terminal using WSL2 in windows 10

I have problem with installing node.js and npm on my Ubuntu terminal (WSL2).
I tried to follow this instructions:
https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl
https://github.com/MicrosoftDocs/windows-uwp/blob/docs/hub/dev-environment/javascript/nodejs-on-wsl.md
Also see some videos on YouTube, but every time I have same error.
First, I run this command:
sudo apt-get install curl
after I am trying to install nvm, with this command :
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
after that it tells, that nvm is installed, but shows some errors(I will include img)
and after that, I can't run this command to verify versions of node.js and npm :
command -v nvm //or this command
nvm ls
I already installed node.js in my windows, and when I open git bash and run this commands node -v and npm -v it shows me, which versions are installed.
But as I use Ubuntu terminal with fish, I wanted to install node.js and npm on it too. Can someone tell me what I am doing wrong?
I believe this may be because you need to restart your terminal, this is one of the troubleshooting tips given from the NVM github page.
There are not any errors when downloading so it is probably just that the .bashrc file was updated but not ran (you should be able to use source ~/.bashrc instead of restarting)

How to update node and npm on my live ubuntu server?

I have rather old version of node and npm on my live server under Digital ocean
node -v
v8.17.0
npm -v
6.13.4
lsb_release -d; uname -r; uname -i
Description: Ubuntu 18.04.5 LTS
4.15.0-122-generic x86_64
Have I just to remove old versions, reboot OS and run :
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
As I have some vue/cli app on my live server Have I to rebuild them all ?
Are there some other steps I have to take ?
Thanks!
As you pointed out that you have some live vue/cli app on server, please be sure before doing an update as it might cause problems to your existing apps if it is live and serving customers currently.
Apart from this you can go with any of the following ways to update Node (and npm).
Use n module from npm as mentioned in this answer.
Via nvm. First install the nvm and then you can install the Node upto latest version.

/usr/bin/env node : not found while executing sudo node

I've a dedicated vps running on cent os. I installed node on that by using
yum install nodejs
It installed successfully without any error and it shows version also.
node -v
v10.16.0
But it shows an error while running this with sudo
sudo node
Command not found
And when I try to run npm with sudo it shows
sudo npm
/usr/bin/env: node: No such file or directory
I tried many solutions from here like
ln -s /usr/bin/nodejs /usr/bin/node
and many more.
I've also tried reinstalling node but still no luck.

Resources