skip to Main Content

I added zsh to my terminal in VSCode and installed nvm.
But every time I open the terminal in vs code, it must re-run

source ~/.nvm/nvm.sh

If not, it will throw an error:

nvm not found and node not found

how to fix it :((

3

Answers


  1. The NVM install script should edit your .zshrc to add 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
    

    This will source the required file needed for NVM to work properly.


    If you installed NVM by hand, you’ll need to place that into your .zshrc (or .bashrc) yourself.

    For more information, please see the installing and updating guide.

    Login or Signup to reply.
  2. In my .zshrc I have following lines:

    export PATH="~/.nvm/versions/node/v22.3.0/bin:$PATH"
    export NVM_DIR=~/.nvm
     [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
    

    This works for me on Ubuntu Linux.

    Login or Signup to reply.
  3. t sounds like the issue is that your terminal isn’t automatically sourcing your NVM (Node Version Manager) configuration when you open it. This typically happens because the startup files for your shell are not correctly sourcing the necessary NVM script.

    As a workaraound, add the following line in your ~/.bashrc file

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
    

    After adding the above line, you’ll need to restart your terminal.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search