nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
80.32k stars 8.03k forks source link

nvm_get_os return nothing on cygwin #2515

Open link89 opened 3 years ago

link89 commented 3 years ago

After installing nvm in Cygwin successfully, I find that whenever I call nvm install 14.0.0, it will always download the source instead of the pre-build binary package.

I find that when I call nvm_get_os in Cygwin, it will return nothing while on my Mac it will return darwin. I think that's the reason why it fails on Cygwin.

However, by creating the following script to test

set -x

nvm_echo() {
  command printf %s\\n "$*" 2>/dev/null
}

nvm_get_os() {
  local NVM_UNAME
  NVM_UNAME="$(command uname -a)"
  local NVM_OS
  case "${NVM_UNAME}" in
    Linux\ *) NVM_OS=linux ;;
    Darwin\ *) NVM_OS=darwin ;;
    SunOS\ *) NVM_OS=sunos ;;
    FreeBSD\ *) NVM_OS=freebsd ;;
    OpenBSD\ *) NVM_OS=openbsd ;;
    AIX\ *) NVM_OS=aix ;;
    CYGWIN* | MSYS* | MINGW*) NVM_OS=win ;;
  esac
  nvm_echo "${NVM_OS-}"
}

nvm_get_os

It returns the right value.

I am not sure if it is the problem of Cygwin or the nvm scirpt.

Software: uname -a CYGWIN_NT-10.0 XMN160 3.1.2(0.340/5/3) 2019-12-21 15:25 x86_64 Cygwin

nvm -v 0.38.0

ljharb commented 3 years ago

This is correct - v0.38.0 doesn't actually support cygwin; see the tagged docs https://github.com/nvm-sh/nvm/tree/v0.38.0#about

The next version will support it, which is the docs you're reading in the default branch.

link89 commented 3 years ago

Good to know this. By the way, I just find that curl may have problems when working with Cygwin. https://github.com/curl/curl/issues/7131 A simple workaround is to use wget as the default download command in nvm_download

ljharb commented 3 years ago

Thanks, that's good to know. It'd be great if you wanted to submit a PR :-) then we can get that in before the cygwin-supporting release.

link89 commented 3 years ago

It turns out to be a problem with the wrong binary of curl. To make it work the curl should be installed via Cygwin. I don't think it is a bug, but it would be good to add to some documents in case other people may have the same issue.

ljharb commented 3 years ago

Thanks, a PR for that would be appreciated too.