nvm: nvm not available in non-interactive shells
See #1717 for installation details. Sorry if you already know these shell details - I had to review them to write this up.
Interactive shells are typed into. E.g. typing the command nvm
at the flashing cursor.
This bug is about nvm not being available in non-interactive shells. E.g. this test.sh:
$ echo -e '#!/bin/bash \n nvm version' > test.sh
$ chmod +x test.sh
$ cat test.sh
#!/bin/bash
nvm version
$ ./test.sh
./test.sh: line 2: nvm: command not found
This is because nvm
isn’t on the path, which probably causes alot of other bugs.
Linking nvm.sh into the path doesn’t work because nvm.sh doesn’t appear to do anything when run directly:
./.nvm/nvm.sh version
<no output>
So, I’m a bit stuck on how to use nvm non-interactively and have to put this crufty code everywhere:
#/bin/bash
[ -s "$HOME/.nvm/nvm.sh" ] && source "$HOME/.nvm/nvm.sh" && nvm install
Which is kind of annoying. It would be nice if nvm was actually installed onto the path.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 18 (8 by maintainers)
To run nvm use via ssh remote command as part of a deployment script doing as ljharb commented makes it work.
@ljharb How do I use nvm in a non-interactive shell without having to source it each time?
nvm.sh
is not runnable, not a binary, never will show up in a PATH, and doesn’t take a version argument. It’s a sourced shell function. Try. ~/.nvm/nvm.sh
.@ljharb I think
nvm-exec
is broken or not installing correctly. It doesn’t seem to do anything in bash or zsh.nvm-exec ls-remote
complained ls-remote wasn’t a command.nvm-exec ls
did a file listing.Aha! Great! Ok @ljharb , that’s the same direction. For whatever reason,
nvm-exec
doesn’t work for me in Zsh or Bashnvm works great, but nvm-exec returns no output. Sunshine means command succeeded. Umbrella w/ rain means the command returned a failure code to the shell.
Am I using it wrong? Or did I miss some documentation?