Search code examples
node.jsnvmzshrc

Node doesn't start without source ~/.bash_profile command


I have to use source ~/.bash_profile for node command to work on my terminal. All the node commands work just fine after using source ~/.bash_profile. I used nvm to install Node LTS(v14.18.0).

My .bash_profile

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

Is there any way to fix my node installation?


Solution

  • MacOS uses zsh as the default shell and not bash. You will need to create a ~/.zshrc file and then run the install script of nvm again.

    You can probably skip the rerunning the install script by manually inserting in .zshrc file the following:

    export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
    

    "Since macOS 10.15, the default shell is zsh and nvm will look for .zshrc to update, none is installed by default. Create one with touch ~/.zshrc and run the install script again." - from nvm docs on github.

    https://github.com/nvm-sh/nvm#troubleshooting-on-macos