Repository: nvm
Issue: Node installed via nvm is not available in tools which weren't run from a terminal
Labels: installing nvm: profile detection


- Operating system and version: 

Ubuntu 18.04 (Version doesn't seem to be relevant, I have seen this behavior on various versions)

- `nvm debug` output:

<details>

```sh
nvm --version: v0.33.11
$SHELL: /bin/bash
$SHLVL: 1
$HOME: /home/norbert-sule
$NVM_DIR: '$HOME/.nvm'
$PATH: $NVM_DIR/versions/node/v10.14.2/bin:$HOME/.local/bin:$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)'
uname -a: 'Linux 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux'
OS version: Ubuntu 18.04.2 LTS  
curl: /usr/bin/curl, curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
wget: /usr/bin/wget, GNU Wget 1.19.4 built on linux-gnu.
git: /usr/bin/git, git version 2.17.1
grep: /bin/grep (grep --color=auto), grep (GNU grep) 3.1
awk: /usr/bin/awk, GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
sed: /bin/sed, sed (GNU sed) 4.4
cut: /usr/bin/cut, cut (GNU coreutils) 8.28
basename: /usr/bin/basename, basename (GNU coreutils) 8.28
rm: /bin/rm, rm (GNU coreutils) 8.28
mkdir: /bin/mkdir, mkdir (GNU coreutils) 8.28
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.7.0-git
nvm current: v10.14.2
which node: $NVM_DIR/versions/node/v10.14.2/bin/node
which iojs: 
which npm: $NVM_DIR/versions/node/v10.14.2/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v10.14.2
npm root -g: $NVM_DIR/versions/node/v10.14.2/lib/node_modules
  ```
  </details>

- `nvm ls` output:
<details>
<!-- do not delete the following blank line -->

```sh
        v8.14.0
->     v10.14.2
default -> 10 (-> v10.14.2)
node -> stable (-> v10.14.2) (default)
stable -> 10.14 (-> v10.14.2) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> v10.14.2)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.15.1 (-> N/A)
lts/carbon -> v8.14.0
lts/dubnium -> v10.14.2
  ```
  </details>

- How did you install `nvm`? (e.g. install script in readme, Homebrew): 

Installed via the snippet from the README.

- What steps did you perform?

* Installed NVM
* Expected WebStorm to be able to detect the installed / default node version.

- What happened?

In the settings of WebStorm a warning tells me that it couldn't find the node binary in PATH and thus I have to specify an absolute path which is not portable. 

The cause is that nvm installs itself to `.bashrc`.

It seems that .bashrc never gets evaluated if you start your desktop and run an app from the desktop environment directly (ie: clicking on an icon, autostart, etc). This results in the app having an environment with a PATH variable which lacks the appropriate node path. 

- What did you expect to happen?

I expect WebStorm to be able to find the node binary.

More broadly: I expect the PATH environment variable inherited from the context of my desktop environment to contain the path of the default node installation.

- Is there anything in any of your profile files (`.bashrc`, `.bash_profile`, `.zshrc`, etc) that modifies the `PATH`?

No, standard Ubuntu install. 

Note:

I have worked around the issue by copying nvm related code to .profile. It is executed right when the user logs in and thus the gui and other tools can inherit the changes to PATH.

According to the bash man page:

>  .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

.bash_profile was not available in my home folder and I don't really have a great understanding on these files so instead I opted to simply use .profile instead. 

Still, based on this fact and the fact that .bashrc is only evaluated when you start a bash shell in the terminal, I wonder why it was chosen as the target for nvm's scripts.