Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to build a script in in which nvm and eventually node will get installed.
I have installed nvm with cURL. I see the modifications in the .profile or .bashrc file (both work) and when typing the nvm at the bash prompt, it shows the options available etc.
So nvm works. Manually I can install node, but as soon as I put the nvm command in a shell script:

nano test.sh

#!/bin/bash
nvm

and run it with:

chmod 755 test.sh
./test.sh

I get:

./test.sh: line 2: nvm: command not found

If it can't find nvm, I don't even have to think of

nvm ls-remote 

or

nvm install ...

I got Ubuntu 14.04 installed and Bash is my shell.

share|improve this question
    
I'd print the path in the script before calling nvm and check if it is correct. – AProgrammer Feb 12 '15 at 17:29
up vote 19 down vote accepted

nvm command is a shell function declared in ~/.nvm/nvm.sh.

You may source either of following scripts at the start of yours to make nvm() available:

. ~/.nvm/nvm.sh
. ~/.profile
. ~/.bashrc
share|improve this answer
    
HI, thanks. This makes sense then as nvm is "installed" in ~/.nvm. And is probably just a shell script. What I am missing though is that I can type nvm and get it to work, but when trying the shell scripts in ~/.nvm it doesn't work. – okidoki Feb 12 '15 at 17:42
    
what do you mean by trying the shell scripts in ~/.nvm? I explained how to run nvm from the shell script above. Is there anything unclear? – webKnjaZ Feb 12 '15 at 17:45
    
To elaborate my last comment. when I "sudo find / -iname nvm*" I find only things in my ~/.nvm folder. Executing the ~/.nvm/nvm-exec or ~/.nvm/nvm.sh (the only files in ~/.nvm, which turn out to be shell scripts) does not give me nvm, like just typing "nvm" on the command line. So where is the link between nvm and the program. – okidoki Feb 12 '15 at 17:47
    
Oh.. I guess nvm is an alias in your shell environment. Please post the output of which nvm and this will clear things out. – webKnjaZ Feb 12 '15 at 17:50
1  
I've installed nvm locally and made some research. nvm is a shell function declared in nvm.sh, so basically you just need to source it with . ~/.nvm/nvm.sh at the beginning of your script (or, as I wrote above, - source .profile/.bashrc) – webKnjaZ Feb 12 '15 at 18:02

If you installed it via brew on OSX, then you can load the brew sourced script into the script env by sourcing it as it details on the install.

I have this in projects to bootstrap them :

brew install nvm
. $(brew --prefix nvm)/nvm.sh
nvm install
...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.