69

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

Community
  • 1
  • 1
user3818576
  • 1,927
  • 5
  • 25
  • 49
  • try out `npm list` then you can see all versions of every package installed. If you want a specific file on mac use `npm list -g | grep (module-name)` – King Reload Apr 18 '17 at 07:27
  • I already get the list using that command. I also get the idea here http://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x. but when I npm install inside the project. I alwayst get this "result env: node: No such file or directory" but If i command it outside my project. It work the npm -v – user3818576 Apr 18 '17 at 07:38
  • you need to set up your server inside the file directory where you installed the npm. – King Reload Apr 18 '17 at 07:41
  • do you have sample for that? I have no idea what file do I need setup. – user3818576 Apr 18 '17 at 07:44
  • https://howtonode.org/how-to-install-nodejs maybe you were trying to install it the wrong way? because mac, windows and linux – King Reload Apr 18 '17 at 07:50
  • npm is Node’s package manager. It is now installed automatically with Node.js so there is no need to do a separate installation. Maybe also nice to know ^ – King Reload Apr 18 '17 at 07:53
  • I used nvm. all modules that I try to install is inside this file User/hello/.nvm/versions/node/v6.10.2/bin/npm. It supposed to be inside user/local/lib – user3818576 Apr 18 '17 at 08:11
  • have you tried moving directories or first removing and then reinstalling in the wanted directory? – King Reload Apr 18 '17 at 08:14
  • Are you on a Mac? If so, why are you running `apt-get` which is a Linux package manager not available on OSX? If you are on a Mac, and you have installed `node` using `homebrew`, you need to either run `/usr/local/bin/node` or add `/usr/local/bin` to your PATH then `node` will work. – Mark Setchell Apr 18 '17 at 08:21
  • @KingReload I trying to uninstall everything now. – user3818576 Apr 18 '17 at 08:22
  • @MarkSetchell how can I add that path? do you have link on how to add it – user3818576 Apr 18 '17 at 08:24
  • before uninstalling, first try to move them to another directory through command line or just copy paste, but your goal is to use npm globally on your computer, correct? – King Reload Apr 18 '17 at 08:26
  • yes, but not in my project – user3818576 Apr 18 '17 at 08:27
  • let us continue in http://chat.stackoverflow.com/rooms/141951/npm-mac – King Reload Apr 18 '17 at 08:37
  • @KingReload - i am also facing a same issue on Jenkins : added same problem in chat can you please have a look at it ? – Swift Apr 19 '17 at 07:30
  • `nvm deactivate nvm uninstall node nvm uninstall npm , brew uninstall --force node , brew uninstall --force npm, nvm install node` – Muhammad Umer Jul 29 '20 at 17:31
  • i faced this issue on iTerm2, node seemed to be available and working in all other tabs, other than where i faced the issue. exited said tab and opened a new one – Paulo Aug 14 '20 at 11:57

8 Answers8

105

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.

jozh
  • 1,561
  • 1
  • 12
  • 13
  • 12
    impatient software engineer like me, always misses warning messages during installation. – vikramvi Jul 22 '19 at 14:49
  • 8
    The last step may fail due to file permissions. In such case `sudo chown -R $(whoami) $(brew --prefix)/*` will help (see https://github.com/nvm-sh/nvm/issues/1702#issuecomment-444309875). This solved my problem, thank you! – Vladimir Vagaytsev Dec 13 '19 at 15:01
74

NOTE: Only mac users!

  1. 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.

  1. 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

  1. 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

  1. Install npm using the following command: npm install -g grunt
Visores
  • 3,446
  • 2
  • 17
  • 29
King Reload
  • 3,430
  • 12
  • 35
  • was having trouble with node but only from within tmux. #1 sorted it out - tmux was looking for node from the nvm path after running the script. – Larry Feb 06 '19 at 13:44
11

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.

RAM237
  • 648
  • 9
  • 14
4

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 !!!

David
  • 930
  • 8
  • 19
1

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.

1

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.

H. Almidan
  • 76
  • 1
  • 5
  • I tried alot of the above solutions (uninstalled everything for starters) but for installing eventually ditched everything else in favor of just downloading it via bash for macOS using the link provided in this answer. and it worked.The curl command is: `curl "https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"` – Sherry Feb 16 '21 at 22:48
1

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.

Noumenon
  • 3,184
  • 4
  • 39
  • 57
0

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.

Farjad
  • 1