Home > database >  Node and npm not found after restarting macOS
Node and npm not found after restarting macOS

Time:02-08

I am using my corporate's laptop and am a new mac User (used Ubuntu before) :

  • OS: macOS Monterey Version 12.2

There are two accounts, administrator and mine - I don't have sudo rights. To install homebrew without administrator rights, I followed this Installation.

To install the node - I used brew install node. Both node -v and npm -v were working. When I restarted the laptop, I cannot find node/npm.

On running $ node -v, I get -bash: node: command not found (I changed my default terminal from zsh to bash and the output is the same for both of them)

I tried this solution but couldn't find nvm in the system. Am new to mac and I believe nvm is some kind of package manager like homebrew so this solution is not applicable to me (correct me if I am wrong).

How can I install things in my system without sudo rights and keep them permanently(like node)?

EDIT:

  • (After adding brew to the PATH) On running - brew list|grep node, I got - node

  • $ echo $PATH gives /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/parthkapadia/homebrew/bin

EDIT2:

  • Adding brew to path solved the issue, now I can even access node and npm (even after restarting). I used this site to add homebrew/bin to path (in zsh terminal)

CodePudding user response:

The issue was homebrew's path. It was not added to the PATH variable. When I restarted the system, homebrew was no longer in the PATH (as it was temporarily added probably when I installed it). As homebrew was not added to PATH, the terminal didn't recognize brew or any package installed using it like node or npm.

I solved it by adding Users/username/homebrew/bin to PATH. The steps I followed are -

  • cd - to move to the home directory
  • touch .zshrc to create .zshrc file as it didn't exist
  • nano .zshrc to open the file for editing
  • Added export PATH=$PATH:/Users/yourusername/homebrew/bin in the file (this appends homebrew/bin to the PATH variable)

Now the terminal can recognize brew and hence node and npm too. Refer this for more detailed explanation on how to add to PATH in macOS.

Thanks to all the people who helped in the comments.

  •  Tags:  
  • Related