node -v and nodejs -v gives me two different version numbers - node.js

Hi I have a node installation on my Linux machine.
When I run node -v command on the terminal, its show me 0.10.32
And when I run nodejs -v, it shows me the same version. i.e 0.10.32
Now I upgraded my node using the following commands:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Now when I run node -v, it shows me the versions as 0.12.7
And when I run nodejs -v, it show me the version as 0.10.32
I am a bit confused with this.
Why are they different, and why do we have node and nodejs, as two separate things?
Please help.
Thanks in advance

Check your node location which node
then remove node
rm -r path/node
Then link your nodejs with node
sudo ln -s which nodejs /usr/bin/node

Related

How to install node.js

I did the following:
user#machine:~$ sudo n stable
installed : v12.13.0 (with npm 6.12.0)
user#machine:~$ node --version
v8.10.0
user#machine:~$ which node
/usr/local/bin/node
user#machine:~$ /usr/local/bin/node --version
v12.13.0
I was expecting v12.13.0 to be installed, but node --version reveals v8.10.0.
What did I do wrong? How do I get v12.13.0 installed? FYI I am on Jetson Nano and I'm really just trying to get LTS Nodejs installed and don't know how.
BTW, if I do sudo apt-get install nodejs I only get v8.10.0.
MORE INFO:
user#machine:~$ node --version
v8.10.0
user#machine:~$ sudo node --version
v12.13.0
Seems sudo is affecting this somehow?
(I'm not very familiar with linux, but I'm learning ... sorry if I'm missing "obvious" stuff.)
I worked around the problem by forgoing the use of n.
Here's how to install directly from the dist at nodejs.org.
wget https://nodejs.org/dist/v12.10.0/node-v12.13.0-linux-arm64.tar.gz
sudo tar -xf node-v12.13.0-linux-arm64.tar.gz --directory /usr/local --strip-components 1
Can't comment but try replacing /usr/bin/node with a symbolic link to /usr/local/bin/node. Had similar issue some time ago that ate my brain. Solved it like this.
P.S don't forget to backup
It's very strange...
Could you try something?
mv /usr/local/bin/node /usr/local/bin/node.back
which node
mv /usr/local/bin/node.back /usr/local/bin/node
I just want to see what produce which if you remove the old node version binary.
Also provide more info about file /usr/local/bin/node, is it a symbolic link? If true, to what?
1) Try opening a new shell and checking what version of node you see there.
n installs the node binary by default to /usr/local/bin/node. You may already have had a node binary installed to /usr/bin/node, and your shell cache of known commands (paths) may be running the old one.
Example of problem with bash: https://github.com/tj/n/issues/588
2) If your OS has the command, you can run which -a node to see if you have multiple versions and where they are installed. (Uninstalling the ones you don't want reduces potential for confusion.)
3) Check the location of the intended version is in your PATH. If you are using n, try running n doctor. There are some extra checks that the version of node found is the one that is the one that n installed.

Deleted nvm now npm is not working

I installed nvm to update my node but then decided to uninstall. After updating my node via website, I am not able to get npm installed despite installing a new version of node and using:
sudo curl -L npmjs.org/install.sh | sudo sh
Here is the message I am getting:
-bash: /Users/SICNARF/.nvm/versions/node/v8.2.1/bin/npm: No such file or directory
I think I just have to change the command from non-existing nvm directory to (wherever its supposed to run).
Node.js version management: no subshells, no profile setup, no convoluted API, just simple.
Installation
npm install -g n
Example
$ n 8.2.1
https://www.npmjs.com/package/n

nodeclipse: command not found on Linux after install it

I have nodejs and npm installed.
I tested npm -v and nodejs -v it worked, showed the current version.
I used the nodeclipse -p command line in my empty folder to create the project structure, but I received the error: command not found
I uninstalled the nodeclipse with npm uninstall and installed again with sudo npm install and did not work.
I used the root account and run the npm install also did not work.
I don´t found the npm or nodejs references to set the environment variable to set the nodeclipse or config it.
Can anyone help please?
Problem
There is a bug in nodeclipse plugin that recognizes Node.js as node command the Windows installation.
In Linux the nodeclipse plugin tries to find the command node and can not find. Why on Linux, the nodejs command is utilized for the Node.js installed.
printing error in the terminal
paranhos#pc-principal:~/workspace-javascript/react-sample$ nodeclipse -p
/usr/bin/env: "node": File or directory not found
Solution: Create a Symbolic Link
sudo ln -s "$ (which nodejs)" /usr/bin/node
or
sudo ln -s /usr/bin/nodejs /usr/bin/node
Successful result
paranhos # pc-main: ~ $ node -v
v4.4.2
paranhos # pc-main: ~ $ nodejs -v
v4.4.2
paranhos # pc-main: ~ $ nodeclipse -h   
Usage: nodeclipse [arguments]   
--help Nodeclipse install > is Nodeclipse CLI Installer Help
I also can solve this question, installing the new nodejs version for my linux distro.
Getting ".deb" package directly and following the instructions in the url´s:
https://nodejs.org/en/download/package-manager/
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
In the version 4.4.7 or latest was Included node and nodejs as command.
Install with npm install -g nodeclipse
then work nodeclipse command
Hope work fine

Sudo user not using same node version

I have a strange issue on my server, when ever i try to install packages with npm that require sudo I run into issues and i have discovered that my su and regular user use different node versions.
$ node -v i get node version 0.10.x
But when i do:
$ sudo node -v i get node version 0.6.x
My su user for some reason is using a different node version than what i normally use and this causes compatibility issues when I npm install packages that require sudo.
I have tried sudo apt-get upgrade nodejs at no luck. how do i make su user use same node version as my regular user.
run ll /usr/bin/node if this file exist, simply run rm /usr/local/bin/node from the regular user
explanation
If you'd run which node from regular user you will probably see it points to the user local bin directory
which node
/usr/local/bin/node
this means that the regular user installed another node version locally.
to let the same node version apply to all users, this command should show you usr bin (not local).
which node
/usr/bin/node
by deleting the link from /usr/local/bin/node it will automatically start using /usr/bin/node
Try running sudo with the environment of the user:
sudo -E node -v
I experienced this problem right after upgrading to a newer version of node (6 -> 7)
The above solution did not work for me as I do not the file /usr/local/bin/node but I was in fact getting different verions from running npm --version and sudo npm --version
https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation
The answer states that bash was caching the older version of node.
simply running hash -d npm

nodejs is already the newest version but "node -v" doesn't give a response

This is really confusing me. If I type "node -v" into the command line, there is no response - it just gives me the $ prompt again. Trying to install node with sudo npm install nodejs gives the response nodejs is already the newest version.
How can I debug this to find out what's going on?
nodejs -v solved the problem.
In some linux distributions node executable is mapped into nodejs.
Are you trying to print the node version? If yes then try
$ node --version
Node is by default installed on /usr/bin/ directory on linux OS it means it should run with normal user privilege but node include some tools that required Superuser privilege so ...
Instead running
node -v
run
sudo node -v
hope it will work...keep coding

Resources