Can't execute nvm from new bash

517 views Asked by At

When I open a new bash, nvm command is not found. It seems that the ~/.nvm/nvm.sh is not being loaded on bash startup.

I have added the line below to ~/.bashrc

[[ -s /home/$USER/.nvm/nvm.sh ]] && . /home/$USER/.nvm/nvm.sh

Any ideas why it is happening?

1

There are 1 answers

0
Alan Sikora On BEST ANSWER

If you are running from a new bash instance, and you HAVE the initialization code at your ~/.bashrc, ~/.bash_profile, etc, then you need to check this initialization file for conditionals.

On Ubuntu 14, there is a:

case $- in
    *i*) ;;
      *) return;;
esac

At line 6, that will halt it's execution if bash is not being ran with the "-i" (interactive) flag. So you would need to run:

bash -i

Also, at the end of the file, there is a

[ -z "$PS1" ] && return

That will halt it's execution if not being ran with $PS1 set (like on a remote ssh session).

If you do not wish to add any env vars or flags, you will need to remove those conditionals from your initialization file.

Hope that's helpful.