Nvm: `set -e`: nvm install lts/[anything] fails

Created on 9 Feb 2017  路  2Comments  路  Source: nvm-sh/nvm

  • Operating system and version: Linux

  • nvm debug output:


nvm --version: v0.33.0
$SHELL: /bin/bash
$HOME: /Users/bjaspan
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: v7.4.0
which node: $NVM_DIR/versions/node/v7.4.0/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v7.4.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v7.4.0
npm root -g: $NVM_DIR/versions/node/v7.4.0/lib/node_modules

  • nvm ls output:

         v6.9.5
->       v7.4.0
default -> node (-> v7.4.0)
node -> stable (-> v7.4.0) (default)
stable -> 7.4 (-> v7.4.0) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> v6.9.5)
lts/argon -> v4.7.3 (-> N/A)
lts/boron -> v6.9.5

  • How did you install nvm? (e.g. install script in readme, homebrew):

Unsure

  • What steps did you perform?

nvm install lts/boron, after running "set -e" in the shell.

  • What happened?

nvm install displayed nvm_ensure_default_set: a version is required and exited with non-zero status.

  • What did you expect to happen?

The lts/boron version should have been installed and nvm install should have exited with zero status.

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?

No.

  • More analysis:

I ran "nvm install lts/boron" in a Bash script with set -e and set -x. I traced through the "nvm install lts/boron" output, following along in the source of the nvm shell function. I discovered a bug in the nvm install command.

  • When you choose install an lts version, it sets the internal "provided_version" variable to the empty string.
  • At the end of the install command, it runs nvm_ensure_default_set "$provided_version". This fails with an error message, "nvm_ensure_default_set: a version is required", which we see in the output, and causes that function to return 1.
  • Because the script is being executed with "set -e", when nvm_ensure_default_set returns 1, it is considered an error and the script exits.

To reproduce, uninstall lts/boron, then install it with set -e enabled, and check that the exit status is 1, whereas if you uninstall it and install it again with set -e disabled, the exit status is zero (the error message is displayed in either case).

The workaround is to use nvm install v6.9.5, which is the version lts/boron actually maps to. This avoids the bug in nvm install, so provided_version remains set, and nvm_ensure_default_set succeeds, and the script exits with status 0 even with set -e.

bugs

Most helpful comment

It works, but it outputs the error message nvm_ensure_default_set: a version is required before succeeding.

All 2 comments

Just to clarify, if you don't have set -e set, everything works with nvm install lts/boron?

Thanks, I want nvm to work with set -e set, but there are still a number of places where it doesn't. I'll look into it.

It works, but it outputs the error message nvm_ensure_default_set: a version is required before succeeding.

Was this page helpful?
0 / 5 - 0 ratings