Exter
Exter

Reputation: 689

Node and npm not found after restarting macOS

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

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:

EDIT2:

Upvotes: 5

Views: 16992

Answers (2)

SparkItUp
SparkItUp

Reputation: 21

For those of you who want to get Node and npm with Nvm, and encounter this issue, I hope this will help you a bit.

I used NVM (Node Version Manager) to get node. After restarting the mac, I found out that Node and npm were missing.

I came to the conclusion that I had to install Xcode (manually from the App Store) first. It is also mentioned at NVM's documentation.

After installing Xcode, I used the command homebrew doctor to see if everything is fine. I had to change the Xcode path, using this command sudo xcode-select --switch /Applications/Xcode.app;. I guess I wouldn't have to do it if I had installed homebrew after getting Xcode from the app store.

So finally, I did install NVM again using this command curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash and everything worked fine.

Upvotes: 2

Exter
Exter

Reputation: 689

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.

Upvotes: 8

Related Questions