user3818576
user3818576

Reputation: 3391

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

Upvotes: 159

Views: 299885

Answers (24)

Sankalp Salve
Sankalp Salve

Reputation: 11

If all of these will answers do not work try using

npm install -g ts-node

this will work for you.

Upvotes: 1

Amin Dannak
Amin Dannak

Reputation: 175

i use n node version manager. I got this error when i switched to a specific node version (16.20.2). I then tried switching to another version and it was fine. so i deleted the problematic version: sudo n uninstall 16.20.2 and tried installing it again sudo n install 16.20.2 and everything was peachy agin.

Upvotes: 0

tamerlaha
tamerlaha

Reputation: 1990

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

Upvotes: 0

Promise Preston
Promise Preston

Reputation: 28800

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

Upvotes: 4

RAITON
RAITON

Reputation: 375

for MAC M1/M2 install Node using the official installer

Upvotes: 1

jacoboneill2000
jacoboneill2000

Reputation: 41

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

Upvotes: 0

twentycent
twentycent

Reputation: 1

just run cmd:

% npm

before

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

on Mac m1 pro

Upvotes: 0

Forrest
Forrest

Reputation: 3490

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.

Upvotes: 0

Farjad
Farjad

Reputation: 19

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.

Upvotes: 2

Saad Farooq
Saad Farooq

Reputation: 99

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/

Upvotes: 0

Mehul Pamale
Mehul Pamale

Reputation: 406

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.

Upvotes: 0

Lex.E
Lex.E

Reputation: 161

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

Upvotes: 16

Erwin W
Erwin W

Reputation: 21

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

Upvotes: 2

Nic Wanavit
Nic Wanavit

Reputation: 2683

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

Upvotes: 0

Jacob Rodal
Jacob Rodal

Reputation: 650

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>

Upvotes: 3

Noumenon
Noumenon

Reputation: 6412

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.

Upvotes: 2

yoges nsamy
yoges nsamy

Reputation: 1435

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

Upvotes: 21

Gadelkareem
Gadelkareem

Reputation: 1087

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

nvm use stable

Upvotes: 7

King Reload
King Reload

Reputation: 2952

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

Upvotes: 95

H. Almidan
H. Almidan

Reputation: 518

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.

Upvotes: 3

David
David

Reputation: 1591

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

Upvotes: 11

RAM237
RAM237

Reputation: 1035

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.

Upvotes: 23

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

Upvotes: 2

jozh
jozh

Reputation: 2692

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.

Upvotes: 212

Related Questions