nvm-sh/nvm

Add support for Windows

lmayorga1980 opened this issue ยท 27 comments

Add support for Windows

Are you using bash on windows? Also there are nvm projects for windows like https://github.com/hakobera/nvmw

Why aren't nvm and nvmw merged into one single project?

Because then anyone wishing to work on nvm would have to test on Windows (a pretty burdensome request), and anyone working on nvmw would have to test on *nix.

@ljharb We can automate these tests with various tools. E.g., Firefox developers don't have to manually test their commits on Windows, Mac, and Linux.

Automated browser and linux testing is a solved problem - I'm not personally familiar with any free/open source solutions for automating non-IE Windows-based testing.

That said, if someone wants to submit a PR that can run automated tests on Windows, that would absolutely clear one of the bigger obstacles to supporting it.

For what it's worth, I recently released nvm for windows. It's not a direct port of this project, but it provides the major functionality. It's written in Go, so theoretically it could support OSX/Linux using the same code base if I/someone felt like tweaking it.

@coreybutler there's already "nvmw" - please do not name your project "nvm", as that's the name of this project.

@ljharb - I wrote mine as a response to the fact nvmw broke after node 0.10.26, and according to the author's comments in an issue, he doesn't know how to fix it... and I found it easier to write something new than keep contributing to that code base.

If it's really a problem to have the name "nvm for windows", I can change it... but as a Windows AND Mac user that has to switch between Operating Systems regularly, I can say I wish there were a consistent cross-OS command. I can't tell you how many times I typed "nvmw" on Mac or "nvm" on Windows. While minor, the user experience is still annoying. This was a first attempt at easing that annoyance.

@creationix - Thoughts about naming? I'm not trying to step on toes here... nvm was the inspiration for my project... I just needed the functionality on Windows and the other available projects weren't solving the problem.

Ah, I wasn't aware nvmw was broken. Even if it wasn't, it's of course always fine to develop an alternative to a tool :-)

Note, I'm not suggesting you shouldn't use an executable named "nvm" for consistency - I'm suggesting that the actual name of the repo/project shouldn't just be "nvm".

@ljharb - fair enough - I renamed the repo to nvm-windows to show some separation.

Thanks! I added a note to the README about Windows options.

Thanks!

You might want to check out http://www.appveyor.com/ for testing the builds on Windows.

Closing this now, since the Windows options are noted in the README.

๐Ÿ‘ for @nschonni suggestion.

Are there any issues with running nvm (for non-Windows) with Cygwin on Windows? I don't see why development has to be done (at least) twice if there is an option get down to the root of all evil.

@winniehell Cygwin / MSYS / Git Bash are fantastic, but there are situations where you want to be able to use a tool in an ordinary cmd.exe Command Prompt or PowerShell session.

For example, you might have some MS-DOS batch .bat scripts that you want to chain together with a Node.js tool, maybe even with a Makefile to coordinate the chain. It's easy for these to conflict, as Cygwin can't run .bat files (open feature request), and Command Prompt can't run nvm.

Why not just support Windows as should be the case since Node.js as a project sees Windows as a first-class citizen? The split projects creates additional issues.

node and npm consider Windows a first-class citizen. That's not necessarily the case with unaffiliated project authors.

In general terms, I don't typically support Windows because the burden of running both manual and automated tests on it is massive. Specific to nvm, it's problematic enough supporting POSIX without having to support an alternative shell paradigm - we don't support fish either for a similar reason.

It sounds like MS's new Windows Subsystem for Linux (WSL) might make it easier for lots of nix command-line projects to support Windows 10:
https://blogs.msdn.microsoft.com/commandline/2016/04/06/bash-on-ubuntu-on-windows-download-now-3/

I know this isn't a perfect solution for nvm on Windows but probably an easy one.

@GitTom once Windows Bash supports the right POSIX syscalls, nvm will work with it. It doesn't quite yet.

I just used nvm successfully using "bash on ubuntu on windows". The install script had some quirks though, the download "failed" until I executed sudo apt-get install git, even though curl was installed:

joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9135  100  9135    0     0  53946      0 --:--:-- --:--:-- --:--:-- 54053
=> Downloading nvm as script to '/home/joris/.nvm'
Failed to download 'https://raw.githubusercontent.com/creationix/nvm/v0.31.4/nvm-exec'

=> Appending source string to /home/joris/.bashrc
bash: line 293: /nvm.sh: No such file or directory
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="/home/joris/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvmjoris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$
joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ sudo apt-get install git curl wget
# ...snip...

joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9135  100  9135    0     0   126k      0 --:--:-- --:--:-- --:--:--  125k
=> Downloading nvm from git to '/home/joris/.nvm'
=> fatal: destination path '/home/joris/.nvm' already exists and is not an empty directory.
Failed to clone nvm repo. Please report this!
joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ rm -rf /home/joris/.nvm
joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9135  100  9135    0     0   167k      0 --:--:-- --:--:-- --:--:--  168k
=> Downloading nvm from git to '/home/joris/.nvm'
=> Cloning into '/home/joris/.nvm'...
remote: Counting objects: 5222, done.
remote: Total 5222 (delta 0), reused 0 (delta 0), pack-reused 5222
Receiving objects: 100% (5222/5222), 1.42 MiB | 966.00 KiB/s, done.
Resolving deltas: 100% (3148/3148), done.
Checking connectivity... done.
* (detached from v0.31.4)
  master

=> Source string already in /home/joris/.bashrc
bash: line 293: /nvm.sh: No such file or directory
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="/home/joris/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvmjoris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ exit
exit

D:\Users\J\Projects\jsdom>bash
joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ echo $NVM_DIR
/home/joris/.nvm
joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ nvm i node
Downloading https://nodejs.org/dist/v6.4.0/node-v6.4.0-linux-x64.tar.xz...
######################################################################## 100.0%
Now using node v6.4.0 (npm v3.10.3)
Creating default alias: default -> node (-> v6.4.0)
joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ node --version
v6.4.0
joris@FOOBAR:/mnt/d/Users/J/Projects/jsdom$ npm --version
3.10.3

Thanks for testing that out!

ibqn commented

Does NVM work in git bash on Windows out of the box? Can someone confirm this?

Does NVM work in git bash on Windows out of the box? Can someone confirm this?

The last time I tried, it works properly if you execute the following:

sudo apt-get install git curl wget
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash

Perhaps this issue should be renamed, "Support for Windows CMD/PowerShell" now since at best, WSL will work and at worse, it will present its own set of issues.

  • BashOnWindows / Windows Subsystem for Linux should work out of the box - if it does not, it's a bug in that software.
  • git bash seems to work as long as sudo apt-get install git curl wget is run beforehand.
  • No other windows support from nvm is forthcoming, unless #1203 / nodejs/TSC#96 is resolved such that nvm enters the node.js foundation.