143

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

17
  • 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) Apr 18, 2017 at 7:27
  • 1
    I already get the list using that command. I also get the idea here stackoverflow.com/questions/11177954/…. 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 Apr 18, 2017 at 7:38
  • 1
    you need to set up your server inside the file directory where you installed the npm. Apr 18, 2017 at 7:41
  • 1
    do you have sample for that? I have no idea what file do I need setup. Apr 18, 2017 at 7:44
  • 1
    howtonode.org/how-to-install-nodejs maybe you were trying to install it the wrong way? because mac, windows and linux Apr 18, 2017 at 7:50

22 Answers 22

190

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.

6
  • 15
    impatient software engineer like me, always misses warning messages during installation.
    – vikramvi
    Jul 22, 2019 at 14:49
  • 15
    The last step may fail due to file permissions. In such case sudo chown -R $(whoami) $(brew --prefix)/* will help (see github.com/nvm-sh/nvm/issues/1702#issuecomment-444309875). This solved my problem, thank you! Dec 13, 2019 at 15:01
  • 1
    Running brew link --overwrite node alone solved the issue for me. Dec 29, 2021 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/<dir>. 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, 2022 at 3:09
  • just running brew link --overwrite node did the trick for me Aug 16, 2022 at 8:56
90

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
1
  • 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 6, 2019 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.

18

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
3
  • 1
    Correct answer for nvm users. Works with fish too, paste the same into ~/.config/fish/config.fish, thanks man.
    – Vlad Rose
    Oct 26, 2022 at 4: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 at 10:57
  • Be praised, Good Man!
    – user776686
    Nov 7 at 17:27
16

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
0
9

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

1
  • 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, 2022 at 9:55
6

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

nvm use stable
0
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.

1
  • 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</a>.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"
    – Sherry
    Feb 16, 2021 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>
1
  • worked for me as workaround Jan 31, 2022 at 2:42
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.

1
  • 1
    I had this error through emacs. Running emacs from the terminal fixed my issue as well. Thank you for this! May 10, 2021 at 6:17
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

2
  • 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, 2021 at 19:08
  • Duplicate Answer.
    – ranka47
    Dec 21, 2021 at 19:08
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.

1
  • 3
    brew link --overwrite node did the job for me, like mentioned in the answer by @jozh
    – jammartin
    Jul 7, 2021 at 14:19
1

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

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.

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

0

just run cmd:

% npm

before

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

on Mac m1 pro

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.