Search code examples
node.jsnpmlinux-mint

Closing the terminal doesnt remember my .profile changes for nvm/npm


I installed nvm/npm using this instruction

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-an-ubuntu-14-04-server (How To Install Using NVM), but everytime I close my terminal, it seems to forget all the settings and I have to do the command: source ~/.profile then select the npm version to make it run again. How can I keep my settings permanent, or at least for the duration of my logged in session? Thanks! (linuxmint 17)


Solution

  • Sourcing ~/.profile

    ~/.profile is typically invoked from a login shell. See http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

    Invoked as an interactive login shell, or with --login

    When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

    Opening a terminal does not typically invoke a login shell. Have you tried rebooting/relogging? Additionally if either ~/.bash_profile or ~/.bash_login exist, then bash won't source ~/.profile. There are two common ways to fix this:

    Option 1

    Move commands from the ~/.profile file to ~/.bash_profile

    Option 2

    Source ~/.profile from ~/.bash_profile:

    [[ -f ~/.profile ]] && . ~/.profile
    

    Default Node version

    You can configure a default node version by aliasing it to default

    To set a default Node version to be used in any new shell, use the alias 'default':

    nvm alias default node
    

    See https://github.com/creationix/nvm