Sudo user not using same node version - linux

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

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

env: node: No such file or directory in mac

I'm searching it in google on how to show the version of node js or how I'm gonna work with npm?
If I do this
npm -v
even I already install it using brew install node. The result is always
env: node: No such file or directory
I already do a lot of command to solve for it, but failed.
these are the command that I already try:
sudo apt-get install nodejs-legacy
sudo ln -s /usr/local/bin/node /usr/bin/node
brew unlink node
brew link node
I can't start the task because of this. help me guys. This work before after I used this command brew link --overwrite node. Now I have problem, i cant work anymore with npm. I'm really new about this. I don't have any idea now on how to fix this.
Update
I already get the list using npm list command. I also get the idea here link but when I npm install inside the project. I alwayst get this "result env: node: No such file or directory",even I command npm -v but If i command it outside my project. It work the npm -v
I solved it this way:
$ brew uninstall --force node
$ brew uninstall --force npm
after it
$ brew install node
which suggested me to overwrite simlinks
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
rm '/usr/local/share/doc/node/gdbinit'
To force the link and overwrite all conflicting files:
brew link --overwrite node
after executing
$ brew link --overwrite node
everything worked again.
NOTE: Only mac users!
uninstall node completely with the commands
curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
Or you could check out this website: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
if this doesn't work, you need to remove node via control panel or any other method. As long as it gets removed.
Install node via this website: https://nodejs.org/en/download/
If you use nvm, you can use:
nvm install node
You can already check if it works, then you don't need to take the following steps with: npm -v and then node -v
if you have nvm installed:
command -v nvm
Uninstall npm using the following command:
sudo npm uninstall npm -g
Or, if that fails, get the npm source code, and do:
sudo make uninstall
If you have nvm installed, then use: nvm uninstall npm
Install npm using the following command: npm install -g grunt
I was getting this env: node: No such file or directory error when running the job through Jenkins.
What I did to fix it - added export PATH="$PATH:"/usr/local/bin/ at the beginning of the script that Jenkins job executes.
If you're switching from bash to oh my zsh, you will need to add nvm's path into the zshrc file.
#Zgpeace's answer here helped solve my issue (on IOS):
Open the .zshrc file. I used nano: nano ~/.zshrc
Add this into the file: export NVM_DIR=~/.nvm
Save changes by typing Ctrl+X --> Yes.
Reload the configuration. Type source $(brew --prefix nvm)/nvm.sh
Test by typing nvm --version.
You'll now be able to see the version. For e.g: 0.37.2
Thanks to this forum.
Sharing my notes below.
macOS Monterey
version 12.2.1
Chip Apple M1
$ brew uninstall --force node
$ brew uninstall --force npm
$ brew install node
$ brew link --overwrite node
$ brew doctor
$ brew cleanup
$ nvm --version
// 0.35.3
$ nvm use stable
// Now using node v17.6.0 (npm v8.5.1)
$ node -v
// v17.6.0
$ npm -v
// 8.5.1
I got such a problem after I upgraded my node version with brew. To fix the problem
1)run $brew doctor to check out if it is successfully installed or not
2) In case you missed clearing any node-related file before, such error log might pop up:
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built.
node
3) Now you are recommended to run brew link command to delete the original node-related files and overwrite new files - $ brew link node.
And that's it - everything works again !!!
It was nvm changing paths for me, this fixed it:
nvm use stable
I re-installed node through this link and it fixed it.
I think the issue was that I somehow got node to be in my /usr/bin instead of /usr/local/bin.
Let's see, I sorted that on a different way. in my case I had as path something like ~/.local/bin which seems that it is not the way it wants.
Try to use the full path, like /Users/tobias/.local/bin, I mean, change the PATH variable from ~/.local/bin to /Users/tobias/.local/bin or $HOME/.local/bin .
Now it works. 🙀🙀🙀
I get this error running npm start through PyCharm on Mac. For that the answer is to start PyCharm from the Terminal with open -a '/Applications/PyCharm.app/'. See https://stackoverflow.com/a/34017083/733092.
For Pycharm Professional, starting from the command line is different. Get the JetBrains Toolbox app, go to Settings, Generate Shell Script, and it will create a ~/pycharm_shell_scripts for you to run.
Working on MacOSx, maven exec not willing to execute a shell script that I could manually execute with desired result. Gave me the same error, solved it as well with
export PATH="$PATH:"/usr/local/bin/ at the beginning of the script
For mac user using the package manager homebrew:
-brew uninstall node
-brew uninstall npm
-brew doctor
-brew link node
-node -v (to check node version)
That's all you need.
For me, this error occurred when I tried to install a package with sudo npm. This fixed it:
sudo env PATH="$PATH:/usr/local/bin/" npm <rest of command>
I was using fish shell and encountered this problem on my m1 macbook air.
install nvm omf install nvm
add nvm to path by creating this file ~/.config/fish/functions/nvm.fish
I use vim so vim ~/.config/fish/functions/nvm.fish
function nvm
bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
install node again nvm install node
It worked for me after that, :) hopefully it does for you too
credit https://eshlox.net/2019/01/27/how-to-use-nvm-with-fish-shell
If you just installed/modified node and if intellij/webstorm or your shell is throwing this error, it's because it has not sourced the environment variables, try restarting the IDE/shell.
I also face this issue on mac. I had installed node using brew. I was able to resolve the issue by following these steps:
uninstall node using the command: brew uninstall --force node
uninstall npm using the command: brew uninstall --force npm
Then install node using the installer provided on the following link: https://nodejs.org/en/download/
Just did an update on my Mac OS which switched my .bash to /zshrc. Here is what I added to my ~/.zshrc file:
export NVM_DIR="/Users/< my name >/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # this loads nvm
Then I did a $ source ~/.zshrc and it refreshed those values.
Double checked my work with nvm --version and it was all good.
just run cmd:
% npm
before
% npx install-peerdeps --dev eslint-config-airbnb
on Mac m1 pro
Kept getting this error, found it it's because NVM wasn't using any version of node. I didn't set this but after using these commands it seemed to fix the error
nvm install lts/*
nvm use lts/*

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

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