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

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

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.

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

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

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

Can't build atom on Linux

I followed these steps to build atom on Linux on my own.
After cloning atom, i tried to run script/build. But i get an error "No such file or directory".
Node v0.10.31
Npm v0.10.31
I don't now how can I run these atom-build-script.
After searching, i found a solution to fix this issue.
[1] after installing node via apt, its command is nodejs, not node like its recommended to use these build-script
[1.1] after removing apt's node installation, i build node by my own
[2] run which node, to find out where you install node
[3] to run the build-script: /opt/node/bin/node your-atom-path/script/build
additional information how to fix from atom-github-build-instructions
"/usr/bin/env: node: No such file or directory
If you get this notice when attempting to script/build, you either do not have Node.js installed, or node isn't identified as Node.js on your machine. If it's the latter, entering sudo ln -s /usr/bin/nodejs /usr/bin/node into your terminal may fix the issue."

Checking version of node returns nothing [duplicate]

This question already has answers here:
nodejs is already the newest version but "node -v" doesn't give a response
(3 answers)
Closed 8 years ago.
I am working on linux(ubuntu 64bit), and I have installed node using the tutorial: http://howtonode.org/how-to-install-nodejs.
Here, now when I am doing node --version, it shows the following output.
abhinav#abhinav:~/node$ node --version
abhinav#abhinav:~/node$ node
abhinav#abhinav:~/node$ node -v
As visible, it does not print anything. What could be the reason for this. Please help?
Try
abhinav#abhinav:~/node$ nodejs --version
Using nodejs -v or nodejs --version will serve your purpose, hopefully. In some cases, executable of node is mapped to nodejs.
You should check your $PATH variables. Simply type $PATH in the console and examine the output. If /usr/local/bin/node isn't there (and its probably not) add to .bashrc (hidden in home folder) or .profile:
export PATH="/usr/local/bin/node"
This will tell bash where to look for the node binary.
You can install Node.js by:
sudo apt-get install nodejs nodejs-dev npm
You can check the version by:
nodejs --version

Resources