README.md 13.0 KB
Newer Older
C
Corey Butler 已提交
1
The [npm](https://docs.npmjs.com/cli/v6/configuring-npm/install#windows-node-version-managers)/[Microsoft](https://docs.microsoft.com/en-us/windows/nodejs/setup-on-windows)/Google recommended **Node.js version manager for _Windows_**.
C
Corey Butler 已提交
2

C
Corey Butler 已提交
3
# This is not the same thing as nvm.
C
Corey Butler 已提交
4
_The original [nvm](https://github.com/nvm-sh/nvm) is a completely separate project for Mac/Linux only._ This project uses an entirely different philosophy and is not just a clone of nvm. Details are listed in the [Why another version manager?](https://github.com/coreybutler/nvm-windows#why-another-version-manager) and [what's the big difference?](https://github.com/coreybutler/nvm-windows#whats-the-big-difference) sections.
C
Corey Butler 已提交
5

C
Corey Butler 已提交
6
## Like this project?
C
Corey Butler 已提交
7

C
Corey Butler 已提交
8
Let people know with a [tweet](https://twitter.com/intent/tweet?hashtags=nodejs&original_referer=http%3A%2F%2F127.0.0.1%3A91%2F&text=Check%20out%20NVM%20for%20Windows!&tw_p=tweetbutton&url=http%3A%2F%2Fgithub.com%2Fcoreybutler%2Fnvm-windows&via=goldglovecb). Better yet, **click the "Sponsor" button** at the top of this screen.
C
Corey Butler 已提交
9

C
Corey Butler 已提交
10
## NOTICES
C
Corey Butler 已提交
11

C
Corey Butler 已提交
12
This repository now uses [Github Discussions](https://github.com/coreybutler/nvm-windows/discussions) for updates. Sponsors also receive occasional email updates. The Gitter channel has been retired in favor of these new features.
C
Corey Butler 已提交
13

C
Corey Butler 已提交
14
Old notices have moved to the [notices wiki entry](https://github.com/coreybutler/nvm-windows/wiki/Notices).
C
Corey Butler 已提交
15

C
Corey Butler 已提交
16 17 18 19
## Common Issues & Resolutions

Please see the [Common Issues](https://github.com/coreybutler/nvm-windows/wiki/Common-Issues) page before posting an issue.

C
Corey Butler 已提交
20
# Node Version Manager (nvm) for Windows
C
Corey Butler 已提交
21

22
[![Open Source Helpers](https://www.codetriage.com/coreybutler/nvm-windows/badges/users.svg)](https://www.codetriage.com/coreybutler/nvm-windows)
M
María Inés Parnisari 已提交
23

C
Corey Butler 已提交
24 25
Manage multiple installations of node.js on a Windows computer.

C
Corey Butler 已提交
26
**tl;dr** Similar (not identical) to [nvm](https://github.com/creationix/nvm), but for Windows. Has an installer. [Download Now](https://github.com/coreybutler/nvm-windows/releases)! This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. However, node 4+ is supported. Remember when running `nvm install` or `nvm use`, you must have Windows administrative rights (to create symlinks).
C
Corey Butler 已提交
27

M
María Inés Parnisari 已提交
28
![NVM for Windows](http://i.imgur.com/BNlcbi4.png)
C
Corey Butler 已提交
29 30

There are situations where the ability to switch between different versions of Node.js can be very
C
Corey Butler 已提交
31
useful. For example, if you want to test a module you're developing with the latest
C
Corey Butler 已提交
32 33
bleeding edge version without uninstalling the stable version of node, this utility can help.

M
María Inés Parnisari 已提交
34
![Switch between stable and unstable versions.](http://i.imgur.com/zHEz8Oq.png)
C
Corey Butler 已提交
35

C
Corey Butler 已提交
36
### Installation & Upgrades
C
Corey Butler 已提交
37

C
Corey Butler 已提交
38
#### _PREREQUISITE:_ Uninstall existing node & npm
C
Corey Butler 已提交
39

C
Corey Butler 已提交
40
Uninstall any existing versions of Node.js before installing NVM for Windows (otherwise you'll have conflicting versions). Delete any existing Node.js installation directories (e.g., "C:\Program Files\nodejs") that might remain. NVM's generated symlink will not overwrite an existing (even empty) installation directory.
41

C
Corey Butler 已提交
42
Delete the existing npm install location (e.g. "C:\Users\\<user>\\AppData\Roaming\npm") to prevent global module conflicts. Remember to backup any global `npmrc` config (e.g. `C:\Users\<user>\AppData\Roaming\npm\etc\npmrc`), or copy the settings to the user config `C:\Users\<user>\.npmrc`.
43 44 45

#### Install nvm-windows

C
Corey Butler 已提交
46
[Download the latest installer](https://github.com/coreybutler/nvm/releases) (comes with an uninstaller). There is also a manual option (see [manual installation](https://github.com/coreybutler/nvm-windows/wiki#manual-installation) in the wiki).
47

C
Corey Butler 已提交
48 49
_If NVM4W doesn't appear to work immediately after installation, restart the terminal/powershell._

C
Corey Butler 已提交
50 51
![NVM for Windows Installer](http://i.imgur.com/x8EzjSC.png)

52 53
#### Reinstall any global utilities

C
Corey Butler 已提交
54
After install, reinstalling global utilities (e.g. yarn) will have to be done for each installed version of node:
A
Andrei K 已提交
55
```
C
Corey Butler 已提交
56 57 58 59
nvm use 14.0.0
npm install -g yarn
nvm use 12.0.1
npm install -g yarn
A
Andrei K 已提交
60
```
C
Corey Butler 已提交
61

62 63 64
### Upgrading nvm-windows

**To upgrade nvm-windows**, run the new installer. It will safely overwrite the files it needs to update without touching your node.js installations. Make sure you use the same installation and symlink folder. If you originally installed to the default locations, you just need to click "next" on each window until it finishes.
C
Corey Butler 已提交
65 66 67

### Usage

68 69
**nvm-windows runs in an Admin shell**. You'll need to start `powershell` or Command Prompt as Administrator to use nvm-windows

C
Corey Butler 已提交
70
NVM for Windows is a command line tool. Simply type `nvm` in the console for help. The basic commands are:
C
Corey Butler 已提交
71

C
Corey Butler 已提交
72
- `nvm arch [32|64]`: Show if node is running in 32 or 64 bit mode. Specify 32 or 64 to override the default architecture.
C
Corey Butler 已提交
73
- `nvm install <version> [arch]`: The version can be a node.js version or "latest" for the latest stable version. Optionally specify whether to install the 32 or 64 bit version (defaults to system arch). Set `[arch]` to "all" to install 32 AND 64 bit versions.
C
Corey Butler 已提交
74
- `nvm list [available]`: List the node.js installations. Type `available` at the end to show a list of versions available for download.
C
Corey Butler 已提交
75 76 77
- `nvm on`: Enable node.js version management.
- `nvm off`: Disable node.js version management (does not uninstall anything).
- `nvm proxy [url]`: Set a proxy to use for downloads. Leave `[url]` blank to see the current proxy. Set `[url]` to "none" to remove the proxy.
C
Corey Butler 已提交
78
- `nvm uninstall <version>`: Uninstall a specific version.
T
Tomáš Hübelbauer 已提交
79
- `nvm use <version> [arch]`: Switch to use the specified version. Optionally specify 32/64bit architecture. `nvm use <arch>` will continue using the selected version, but switch to 32/64 bit mode based on the value supplied to `<arch>`. For information about using `use` in a specific directory (or using `.nvmrc`), please refer to [issue #16](https://github.com/coreybutler/nvm-windows/issues/16).
C
Corey Butler 已提交
80 81
- `nvm root <path>`: Set the directory where nvm should store different versions of node.js. If `<path>` is not set, the current root will be displayed.
- `nvm version`: Displays the current running version of NVM for Windows.
82 83
- `nvm node_mirror <node_mirror_url>`: Set the node mirror.People in China can use *https://npm.taobao.org/mirrors/node/*
- `nvm npm_mirror <npm_mirror_url>`: Set the npm mirror.People in China can use *https://npm.taobao.org/mirrors/npm/*
C
Corey Butler 已提交
84 85 86

### Gotcha!

87
Please note that any global npm modules you may have installed are **not** shared between the various versions of node.js you have installed. Additionally, some npm modules may not be supported in the version of node you're using, so be aware of your environment as you work.
C
Corey Butler 已提交
88

C
Corey Butler 已提交
89 90
### Antivirus

L
Leong Jia Meng 已提交
91
Users have reported some problems using antivirus, specifically McAfee. It appears the antivirus software is manipulating access to the VBScript engine. See [issue #133](https://github.com/coreybutler/nvm-windows/issues/133) for details and resolution.
C
Corey Butler 已提交
92

C
Corey Butler 已提交
93 94
As of 1.1.7, the executable and installation files are code-signed by [Ecor Ventures LLC](https://ecorventures.com)/[Author.io](https://author.io). This should help prevent false positives with most antivirus software.

C
Corey Butler 已提交
95 96 97 98 99 100
### Using Yarn

**tldr;** `npm i -g yarn`

See the [wiki](https://github.com/coreybutler/nvm-windows/wiki/Common-Issues#how-do-i-use-yarn-with-nvm-windows) for details.

N
Narve Sætre 已提交
101 102 103 104 105 106 107 108
### Build from source

- Install go from http://golang.org
- Download source / Git Clone the repo
- Change GOARCH to amd64 in build.bat if you feel like building a 64-bit executable
- Fire up a Windows command prompt and change directory to project dir
- Execute `go get github.com/blang/semver`
- Execute `go get github.com/olekukonko/tablewriter`
N
Narve Sætre 已提交
109
- Execute `build.bat`
N
Narve Sætre 已提交
110 111 112
- Check the `dist`directory for generated setup program. 


N
Narve Sætre 已提交
113 114
---

N
Narve Sætre 已提交
115 116


C
Corey Butler 已提交
117 118
## Why another version manager?

119
There are several version managers for node.js. Tools like [nvm](https://github.com/creationix/nvm) and [n](https://github.com/tj/n)
C
Corey Butler 已提交
120
only run on Mac OSX and Linux. Windows users are left in the cold? No. [nvmw](https://github.com/hakobera/nvmw) and [nodist](https://github.com/marcelklehr/nodist)
C
Corey Butler 已提交
121 122
are both designed for Windows. So, why another version manager for Windows?

C
Corey Butler 已提交
123 124 125
The architecture of most node version managers for Windows rely on `.bat` files, which do some clever tricks to set or mimic environment variables.
Some of them use node itself (once it's downloaded), which is admirable, but prone to problems. Right around node 0.10.30, the installation
structure changed a little, causing some of these to just stop working with anything new.
C
Corey Butler 已提交
126

C
Corey Butler 已提交
127 128 129 130 131
Additionally, some users struggle to install these modules since it requires a little more knowledge of node's installation structure. I believe if it
were easier for people to switch between versions, people might take the time to test their code on back and future versions... which is
just good practice.

## What's the big difference?
C
Corey Butler 已提交
132

133
First and foremost, this version of nvm has no dependency on node. It's written in [Go](https://golang.org/), which is a much more structured
C
Corey Butler 已提交
134 135
approach than hacking around a limited `.bat` file. It does not rely on having an existing node installation. Go
offers the ability to create a Mac/Linux version on the same code base. In fact, this is already underway.
C
Corey Butler 已提交
136 137 138 139 140 141 142 143

The control mechanism is also quite different. There are two general ways to support multiple node installations with hot switching capabilities.
The first is to modify the system `PATH` any time you switch versions, or bypass it by using a `.bat` file to mimic the node executable and redirect
accordingly. This always seemed a little hackish to me, and there are some quirks as a result of this implementation.

The second option is to use a symlink. This concept requires putting the symlink in the system `PATH`, then updating its target to
the node installation directory you want to use. This is a straightforward approach, and seems to be what people recommend.... until they
realize just how much of a pain symlinks are on Windows. This is why it hasn't happened before.
C
Corey Butler 已提交
144

C
Corey Butler 已提交
145
In order to create/modify a symlink, you must be running as an admin, and you must get around Windows UAC (that annoying prompt). Luckily, this is
146
a challenge I already solved with some helper scripts in [node-windows](https://github.com/coreybutler/node-windows). As a result, NVM for Windows
C
Corey Butler 已提交
147 148 149 150
maintains a single symlink that is put in the system `PATH` during installation only. Switching to different versions of node is a matter of
switching the symlink target. As a result, this utility does **not** require you to run `nvm use x.x.x` every time you open a console window.
When you _do_ run `nvm use x.x.x`, the active version of node is automatically updated across all open console windows. It also persists
between system reboots, so you only need to use nvm when you want to make a change.
C
Corey Butler 已提交
151

C
Corey Butler 已提交
152
NVM for Windows comes with an installer, courtesy of a byproduct of my work on [Fenix Web Server](http://fenixwebserver.com).
C
Corey Butler 已提交
153

C
Updated  
Corey Butler 已提交
154
Overall, this project brings together some ideas, a few battle-hardened pieces of other modules, and support for newer versions of node.
C
Corey Butler 已提交
155

C
Corey Butler 已提交
156
NVM for Windows recognizes the "latest" versions using a [list](https://nodejs.org/download/release/index.json) provided by the Node project. Version 1.1.1+ use this list. Before this list existed, I was scraping releases and serving it as a standalone [data feed](https://github.com/coreybutler/nodedistro). This list was used in versions 1.1.0 and prior, but is now deprecated.
C
Corey Butler 已提交
157

C
Updated  
Corey Butler 已提交
158
## Motivation
C
Corey Butler 已提交
159

160
I needed it, plain and simple. Additionally, it's apparent that [support for multiple versions](https://github.com/nodejs/node-v0.x-archive/issues/8075) is not
C
Updated  
Corey Butler 已提交
161
coming to node core, or even something they care about. It was also an excuse to play with Go.
C
Corey Butler 已提交
162

C
Corey Butler 已提交
163 164 165 166
## Why Go? Why not Node?

I chose Go because it is cross-platform, felt like less overhead than Java, has been around longer than most people think, and I wanted to experiment with it. I've been asked why I didn't write it with Node. Trying to write a tool with the tool you're trying to install doesn't make sense to me. As a result, my project requirements for this were simple... something that's not Node. Node will continue to evolve and change. If you need a reminder of that, io.js. Or consider all the breaking changes between 4.x.x and 6.x.x. These are inevitable in the world of software.

C
Corey Butler 已提交
167 168
## License

C
Corey Butler 已提交
169
MIT.
C
Corey Butler 已提交
170

C
Corey Butler 已提交
171 172 173 174 175 176 177 178 179
## Sponsors

<table cellpadding="10" cellspacing="0" border="0">
  <tr>
    <td><a href="https://metadoc.io"><img src="https://github.com/coreybutler/staticassets/raw/master/sponsors/metadoclogobig.png" width="200px"/></a></td>
    <td><a href="https://butlerlogic.com"><img src="https://github.com/coreybutler/staticassets/raw/master/sponsors/butlerlogic_logo.png" width="200px"/></a></td>
  </tr>
</table>

C
Corey Butler 已提交
180 181
## Thanks

C
Corey Butler 已提交
182 183 184 185 186
Thanks to everyone who has submitted issues on and off Github, made suggestions, and generally helped make this a better project. Special thanks to 

- [@vkbansal](https://github.com/vkbansal), who provided significant early feedback throughout the early releases.
- [@rainabba](https://github.com/rainabba) and [@sullivanpt](https://github.com/sullivanpt) for getting Node v4 support integrated.
- [@s-h-a-d-o-w](https://github.com/s-h-a-d-o-w) who resolved the longstanding space escaping issue in path names ([#355](https://github.com/coreybutler/nvm-windows/pull/355)).