Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvm.sh fails to source on initial install #35

Closed
mheffner opened this issue May 11, 2011 · 15 comments
Closed

nvm.sh fails to source on initial install #35

mheffner opened this issue May 11, 2011 · 15 comments

Comments

@mheffner
Copy link

After following the installation instructions in the README, the nvm.sh script fails to source in bash. It will return with error code 13.

After investigation, it appears the you must install a node version AND alias it to default before the script will source without error. It tries to find the active version by performing an ls on the install directory, and upon failing to find an installed version, returns error code 13.

On initial install, the failure to find an installed node version should be a handled error. In my case, I assumed it was broken when it was returning code 13.

@creationix
Copy link
Collaborator

That sounds a bit of a chicken and egg problem. On my bash in a vanilla Ubuntu system, I never have trouble sourcing nvm in a clean environment. Do you have anything custom or aliases setup?

@mheffner
Copy link
Author

What is the value of $? after sourcing nvm.sh? With the current master, mine is always '13' before I've installed a particular node version. I can also trigger this by simply removing the default alias:

$ source ~/.nvm/nvm.sh 
$ echo $?
0
$ rm ~/.nvm/alias/default 
$ source ~/.nvm/nvm.sh 
Exit 13
$ echo $?
13

Restoring the alias default removes the failure. My recommendation would be to remove the 'return 13' in the case it can't find an installed node version and only error when someone attempts to pick a node version that doesn't exit.

FWIW, the following bashrc function helps diagnose commands that fail by printing the return value of the previous command if not zero:

# Display exit status of previous command on failure
#
function printexitvalue()
{
        local SAVE_EXIT=$?

        if [ $SAVE_EXIT -ne 0 ]; then
           echo "Exit $SAVE_EXIT";
        fi

        return $SAVE_EXIT
}
export PROMPT_COMMAND=printexitvalue

@creationix
Copy link
Collaborator

Sorry, I didn't see your comment. Did you ever resolve this?

@mheffner
Copy link
Author

I believe I worked around it by ignoring the error and preceding with installing a node and setting it as default. I'd imagine the original error is still present though, see earlier comment for how to reproduce.

@creationix
Copy link
Collaborator

I understand. Nothing is broken, it's just that in your environment, you're able to see the error code that I can't see in a vanilla bash environment. I'll look into fixing it if it bothers more people.

@KrofDrakula
Copy link

I think I'm having the same problem; installed a fresh Ubuntu 11.04 system and sourced nvm. Tried nvm install stable: it downloads the source but errors out with the following:

nvm: install v0.4.11 failed!

It does download the source to the current directory, though.

ADDED: I've additionally installed build-essential, openssl and libssl-dev to no avail. Node's ./configure shows all green.

@KrofDrakula
Copy link

Okay, installing the latest node from master branch using the following:

./configure
make
sudo make install

And then opening a new shell (while having . ~/.nvm/nvm.sh in my .bashrc) and running nvm install stable from my home directory seems to have done its job.

As a side effect, I've now seen that the nvm install behaves differently; in previous attempts it showed the standard curl messages (progress bars and all), while this time round it showed the familiar hash signs and counted up to 100%. If that helps any, I'm really bad at bash and can't point my finger to any of the parts of the sourced script.

@siygle
Copy link

siygle commented Oct 16, 2011

I have the same problem when I upgrade my laptop to ubuntu 11.10. I didn't install any nodejs package at first, then I tried to install nodejs through nvm, but it always display "install failed!" (Both v0.4.x & v0.5.x)

I put some debug code and find out that
https://github.com/creationix/nvm/blob/master/nvm.sh#L106-110
The if else not work correctly, so the tarball would be null then program goes fail.

Then I do the same thing just like KrofDrakula did, fetch the node source code and install. After that, nvm could work fine.
Any advice? Thank.

@jprichardson
Copy link

I also have the same problem. On a vanilla Ubuntu 11.10, NVM fails to install v0.4.12. However, it seems to have downloaded the tarball correctly. Any thoughts on the problem?

@jprichardson
Copy link

I figured out the problem... for some reason on Ubuntu 11.10, emulation with curl is happening from the nvm.sh script. Remove that portion in the beginning of the nvm.sh file and source the update. Then make sure that the actual curl binary is installed.

Why any dependence upon wget? Why not just a dependence upon curl? Why bother trying to emulate curl with wget?

@creationix
Copy link
Collaborator

Desktop Linux doesn't usually have curl installed by default, but it does have wget. I always install curl and I think any serious web developer should have curl, but I'm not sure I should force that opinion on others. Either way, the wget emulation doesn't seem to work so I should probably remove it.

@KrofDrakula
Copy link

I'd suggest the script check the availability of curl and get rid of the use of wget altogether. If curl is not available, simply fail with an error message stating that curl needs to be installed as a prerequisite.

EDIT: just tried the suggestion by @jprichardson – installing curl on a vanilla Ubuntu instance (11.04) prior to running nvm install v0.4.12 does the trick, if anyone's still stuck.

@creationix
Copy link
Collaborator

Fixed in 8dad534

@KrofDrakula
Copy link

Awesome, thanks. Informative errors are way cool. :)

@jprichardson
Copy link

Excellent! Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants