141

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
  • 2,979
  • 8
  • 37
  • 62
  • 1
    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
  • 1
    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
  • 1
    you need to set up your server inside the file directory where you installed the npm. – King Reload Apr 18 '17 at 07:41
  • 1
    do you have sample for that? I have no idea what file do I need setup. – user3818576 Apr 18 '17 at 07:44
  • 1
    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

22 Answers22

183

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
  • 2,412
  • 2
  • 15
  • 15
  • 15
    impatient software engineer like me, always misses warning messages during installation. – vikramvi Jul 22 '19 at 14:49
  • 14
    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
  • 1
    Running `brew link --overwrite node` alone solved the issue for me. – Tamás Sengel Dec 29 '21 at 12:53
  • If you installed a previous version using `sudo` like me, pay close attention to the output when it fails. There will be several directories in "Cellar" that you will need to `sudo rm -rf /usr/local/Cellar/`. After each, make sure to repeat the `uninstall --force steps`. I had 3 or 4 before I finally got a successful installation, but this solution is the basis for success. – Jesse Q Mar 20 '22 at 03:09
  • just running brew link --overwrite node did the trick for me – Lars Christoffersen Aug 16 '22 at 08:56
  • This works beautifully `sudo chown -R $(whoami) $(brew --prefix)/*` – Alex Oct 06 '22 at 17:24
89

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
  • 4,008
  • 4
  • 18
  • 29
King Reload
  • 2,780
  • 1
  • 17
  • 42
  • 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
20

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
  • 903
  • 11
  • 17
16

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):

  1. Open the .zshrc file. I used nano: nano ~/.zshrc
  2. Add this into the file: export NVM_DIR=~/.nvm
  3. Save changes by typing Ctrl+X --> Yes.
  4. Reload the configuration. Type source $(brew --prefix nvm)/nvm.sh
  5. Test by typing nvm --version.
  6. You'll now be able to see the version. For e.g: 0.37.2
yoges nsamy
  • 1,275
  • 1
  • 16
  • 29
  • 1
    Correct answer for `nvm` users. Works with fish too, paste the same into `~/.config/fish/config.fish`, thanks man. – Vlad Rose Oct 26 '22 at 04:52
  • 1
    Annoying that oh my zsh breaks these things. I just noticed it does make a handy file `~/.zshrc.pre-oh-my-zsh` for you to go find your old set-up in! – Harry Wood Jan 12 '23 at 10:57
14

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
Lex.E
  • 141
  • 1
  • 2
8

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
  • 1,365
  • 14
  • 23
  • I found it a bit risky to re-install node, since I am using NVM. I have tried `brew doctor`. This was not successful, but re-installing zsh worked just fine for me: `brew install zsh`. This took 10 min and felt risk free. – lukas_o Mar 23 '22 at 09:55
6

It was nvm changing paths for me, this fixed it:

nvm use stable
Gadelkareem
  • 1,067
  • 13
  • 30
3

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
  • 431
  • 4
  • 9
  • 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
3

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>
Jacob Rodal
  • 620
  • 1
  • 6
  • 12
2

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.

2

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.

Noumenon
  • 5,099
  • 4
  • 53
  • 73
2

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.

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
Farjad
  • 19
  • 2
2

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

Erwin W
  • 21
  • 1
  • 1
    Welcome to SO. A similar answers already exists. Please edit the answer if you feel there is something new to add. You can also upvote the answer that you feel may resolve the question. – ranka47 Dec 21 '21 at 19:08
  • Duplicate Answer. – ranka47 Dec 21 '21 at 19:08
0

I was using fish shell and encountered this problem on my m1 macbook air.

  1. install nvm omf install nvm
  2. 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
  1. 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

Nic Wanavit
  • 2,363
  • 5
  • 19
  • 31
0

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.

Mehul Pamale
  • 349
  • 3
  • 13
0

I also face this issue on mac. I had installed node using brew. I was able to resolve the issue by following these steps:

  1. uninstall node using the command: brew uninstall --force node
  2. uninstall npm using the command: brew uninstall --force npm
  3. Then install node using the installer provided on the following link: https://nodejs.org/en/download/
Saad Farooq
  • 39
  • 1
  • 8
0

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.

Forrest
  • 2,968
  • 1
  • 27
  • 18
0

just run cmd:

% npm

before

% npx install-peerdeps --dev eslint-config-airbnb

on Mac m1 pro

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

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/*
0

for MAC M1/M2 install Node using the official installer

RAITON
  • 325
  • 2
  • 13
0

The issue was caused by no node application being installed.

When I run the command:

node --version

I get no node version:

zsh: command not found: node

I ran the following commands to fix it:

brew uninstall --force node
brew uninstall --force npm
brew doctor
brew install nvm
brew install yarn
brew install node
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
0

I tried couple methods here, but later I recalled I'm some kind of admin :) so I just linked files like so (you version and path might be different and assuming node is installed already):

ln -s /usr/local/Cellar/node@14/14.21.3_1/bin/node /usr/local/bin/node
ln -s /usr/local/Cellar/node@14/14.21.3_1/bin/npm /usr/local/bin/npm
tamerlaha
  • 1,902
  • 1
  • 17
  • 25