Nvm and Node keep going missing upon closing terminal
Asked Answered
B

2

5

Hoping you can help me figure out this issue!

I just bought a new MacBook and was getting my development environment set up today. I installed XCode, Brew, NVM, and Git. When I installed Git, I had to change it so it was the first in the path so I could avoid using Apple Git, and I think that severely messed things up.

For some reason, nvm was not showing when I was running: nvm ls or nvm ls-remote

Yet when I told brew to install nvm, it said it was already installed. OK. Eventually was able to get it sorted out and install node and such.

Fast forward to now, I went to run node in the terminal. Node was not found. Did some research and found that I should not install nvm with homebrew, so I did brew uninstall nvm and brew cleanup and then installed through the recommend github repository.

I ran the necessary commands and added to my PATH, and when I ran command -v nvm, nvm was returned. GREAT. Then I ran the other commands to install Node and I was able to use it, until I closed the terminal.

Now when I reopen the terminal and run node, it returns command not found. Command -v nvm does not return anything too.

Please help - it's been such a headache and I can't seem to figure out whats going on. Every solution I'm finding on Stack Overflow works until I close the terminal.

Blenheim answered 21/1, 2020 at 21:26 Comment(2)
Add your own answer, which could be upvoted!Kissiah
@Kissiah thank you! I didn't know I could do that!Blenheim
B
10

I was able to figure it out. The command all NVM guides tell you to run in order to start running node was not properly added to .bashrc.

Use these as a reference if you have the same issue as me: https://itnext.io/nvm-the-easiest-way-to-switch-node-js-environments-on-your-machine-in-a-flash-17babb7d5f1b .bashrc: Permission denied

Blenheim answered 21/1, 2020 at 23:45 Comment(2)
Yes! Basically you just need to add following lines to your .bashrc file: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completionHillery
same issue as above, ran nvm alias default node per the link and restarted terminal, seemed to resolve the issueOleaster
N
1

I had the same issue in Ubuntu. In my case it was fixed by setting the current version of Node.js as the default:

nvm alias default node

This command ensures that the current version of Node.js is used as the default in new terminal sessions, which fixed the issue with npm not being found.

Nicky answered 23/8 at 19:1 Comment(1)
This worked for me. ThanksEndres

© 2022 - 2024 — McMap. All rights reserved.