blob: d8d8a371539fcd39a9d1fb4ce5390415277952a1 [file] [log] [blame]
Jordan Harband77f44902014-04-25 10:43:22 -07001# Node Version Manager [![Build Status](https://travis-ci.org/creationix/nvm.svg?branch=master)][3]
creationixbb495472010-04-15 10:00:34 -07002
3## Installation
4
Jordan Harband9d9cfdc2014-10-04 16:38:56 -07005First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential and libssl-dev packages work.
creationix4feb4e32010-04-15 10:06:53 -07006
Jordan Harband9d23f602014-10-04 16:40:15 -07007Note: `nvm` does not support Windows (see [#284](https://github.com/creationix/nvm/issues/284)). Two alternatives exist, which are not supported nor developed by us:
Jacob Hoffman-Andrews896a7ed2015-01-18 12:05:44 -08008 - [nvmw](https://github.com/hakobera/nvmw)
9 - [nvm-windows](https://github.com/coreybutler/nvm-windows)
Jordan Harband9d23f602014-10-04 16:40:15 -070010
Félix Saparelli2db71a82015-02-08 11:31:31 +130011Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creationix/nvm/issues/303)). Two alternatives exist, which are not supported nor developed by us:
12 - [nvm-fish-wrapper](https://github.com/passcod/nvm-fish-wrapper)
13 - [nvm-fish](https://github.com/Alex7Kom/nvm-fish) (does not support iojs)
14
Koen Puntb063b322012-12-04 23:21:00 +010015### Install script
16
Jordan Harband77f44902014-04-25 10:43:22 -070017To install you could use the [install script][2] using cURL:
Koen Puntb063b322012-12-04 23:21:00 +010018
Jordan Harbandd78722b2015-05-29 11:11:40 -070019 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
Koen Puntb063b322012-12-04 23:21:00 +010020
21or Wget:
22
Jordan Harbandd78722b2015-05-29 11:11:40 -070023 wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
Koen Puntb063b322012-12-04 23:21:00 +010024
Koen Punt9f628022013-12-22 18:37:08 +010025<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
Koen Puntb063b322012-12-04 23:21:00 +010026
Jordan Harbanda7b1f932014-10-19 19:28:09 -040027You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR`, and `PROFILE` variables.
28Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install.
Koen Punt9f628022013-12-22 18:37:08 +010029
Jordan Harbanda7b1f932014-10-19 19:28:09 -040030<sub>*NB. The installer can use `git`, `curl`, or `wget` to download `nvm`, whatever is available.*</sub>
Koen Puntb063b322012-12-04 23:21:00 +010031
32### Manual install
33
Jordan Harband9d9cfdc2014-10-04 16:38:56 -070034For manual install create a folder somewhere in your filesystem with the `nvm.sh` file inside it. I put mine in a folder called `nvm`.
Tim Caswell6c243e52010-04-15 12:14:52 -050035
Jordan Harband199ba532014-09-13 00:59:09 -070036Or if you have `git` installed, then just clone it, and check out the latest version:
Tim Caswell6c243e52010-04-15 12:14:52 -050037
Jordan Harbandf6fef752014-09-13 11:37:19 -070038 git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
creationixbb495472010-04-15 10:00:34 -070039
Fraser Tweedale58033252013-08-10 19:30:25 +100040To activate nvm, you need to source it from your shell:
creationixbb495472010-04-15 10:00:34 -070041
Marc-Aurèle DARCHE4612d8d2015-04-19 16:25:34 +020042 . ~/.nvm/nvm.sh
Tim Caswella078d642010-12-10 11:42:19 -080043
Fraser Tweedale58033252013-08-10 19:30:25 +100044I always add this line to my `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login.
Tim Caswella078d642010-12-10 11:42:19 -080045Often I also put in a line to use a specific version of node.
Jing Dong6a98d162013-08-15 19:25:51 +010046
creationixbb495472010-04-15 10:00:34 -070047## Usage
48
Jordan Harbandc0c5e8d2014-05-04 02:20:24 -070049You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).
Jordan Harbandf408d682014-12-17 01:30:23 -080050`nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will all respect an `.nvmrc` file when a version is not supplied.
Jordan Harbandc0c5e8d2014-05-04 02:20:24 -070051
Jordan Harband1e353b22013-06-14 09:14:37 -070052To download, compile, and install the latest v0.10.x release of node, do this:
creationixbb495472010-04-15 10:00:34 -070053
Jordan Harband1e353b22013-06-14 09:14:37 -070054 nvm install 0.10
creationixbb495472010-04-15 10:00:34 -070055
56And then in any new shell just use the installed version:
57
Jordan Harband1e353b22013-06-14 09:14:37 -070058 nvm use 0.10
creationix112f7392010-04-15 10:03:42 -070059
Maciej Małecki335a2532011-10-29 10:04:37 +020060Or you can just run it:
61
Jordan Harbandc0c5e8d2014-05-04 02:20:24 -070062 nvm run 0.10 --version
Maciej Małecki335a2532011-10-29 10:04:37 +020063
Jordan Harbanda703d352014-08-02 19:22:53 -070064Or, you can run any arbitrary command in a subshell with the desired version of node:
Jordan Harbandd5c0e942014-08-01 01:26:33 -070065
66 nvm exec 0.10 node --version
67
Daniel Bretoic9a53fe2014-11-21 17:55:46 -080068You can also get the path to the executable to where it was installed:
69
70 nvm which 0.10
71
Jordan Harbandacfc4592014-09-29 21:43:58 -070072In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":
73
74 nvm install stable
75 nvm install unstable
76 nvm use stable
77 nvm run unstable --version
Jordan Harbandd90c1ec2015-01-23 02:08:13 -080078
G. Kay Lee3e74bac2015-01-25 15:29:36 +080079If you want to install [io.js](https://github.com/iojs/io.js/):
Mikeal Rogers0471d0f2015-01-20 10:21:18 -050080
81 nvm install iojs
Jordan Harbandacfc4592014-09-29 21:43:58 -070082
83If you want to use the system-installed version of node, you can use the special default alias "system":
84
85 nvm use system
86 nvm run system --version
87
Hugo Josefsone4acd632013-03-04 12:54:42 +010088If you want to see what versions are installed:
creationix112f7392010-04-15 10:03:42 -070089
Tim Caswell91d2be52010-12-10 11:32:16 -080090 nvm ls
Tim Caswell1938f692010-05-06 18:33:46 -050091
Hugo Josefsone4acd632013-03-04 12:54:42 +010092If you want to see what versions are available to install:
93
94 nvm ls-remote
95
Tim Caswell91d2be52010-12-10 11:32:16 -080096To restore your PATH, you can deactivate it.
97
98 nvm deactivate
99
Isaac Wolkerstorfer86176632011-01-22 19:16:24 +0100100To set a default Node version to be used in any new shell, use the alias 'default':
101
Jordan Harbandacfc4592014-09-29 21:43:58 -0700102 nvm alias default stable
Isaac Wolkerstorfer86176632011-01-22 19:16:24 +0100103
Jordan Harbandecb7a152014-01-31 10:00:19 -0800104To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
Kyle Kelley8599ea22014-01-30 19:22:44 -0800105
Jacob Hoffman-Andrews896a7ed2015-01-18 12:05:44 -0800106 export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
Kyle Kelley8599ea22014-01-30 19:22:44 -0800107 nvm install 0.10
108
Jacob Hoffman-Andrews896a7ed2015-01-18 12:05:44 -0800109 NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 0.10
Jordan Harbandecb7a152014-01-31 10:00:19 -0800110
yeloc8f712a2015-01-23 11:18:51 +0800111To use a mirror of the iojs binaries, set `$NVM_IOJS_ORG_MIRROR`:
112
113 export NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
114 nvm install iojs-v1.0.3
115
116 NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3
117
Jordan Harbandca89cce2014-10-14 17:38:42 -0700118`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs.
Jordan Harbanda00a3a72014-09-03 00:07:45 -0700119
Tim Caswell7d4b1242012-07-20 08:30:13 -0500120## License
121
Jordan Harband1478c722013-08-20 10:39:44 -0700122nvm is released under the MIT license.
Tim Caswell7d4b1242012-07-20 08:30:13 -0500123
124
PatrickJS50485d62014-02-03 17:07:56 -0800125Copyright (C) 2010-2014 Tim Caswell
Tim Caswell7d4b1242012-07-20 08:30:13 -0500126
127Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
128
129The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
130
131THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
132
Thomas Levinea27d3912012-10-10 19:17:09 -0400133## Running tests
Jordan Harband77f44902014-04-25 10:43:22 -0700134Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
Thomas Levinea27d3912012-10-10 19:17:09 -0400135
Jordan Harband9021cf52013-12-17 13:09:55 -0800136 npm install
Thomas Levinea27d3912012-10-10 19:17:09 -0400137
138There are slow tests and fast tests. The slow tests do things like install node
139and check that the right versions are used. The fast tests fake this to test
140things like aliases and uninstalling. From the root of the nvm git repository,
141run the fast tests like this.
142
Jordan Harband9021cf52013-12-17 13:09:55 -0800143 npm run test/fast
Thomas Levinea27d3912012-10-10 19:17:09 -0400144
145Run the slow tests like this.
146
Jordan Harband9021cf52013-12-17 13:09:55 -0800147 npm run test/slow
Thomas Levinea27d3912012-10-10 19:17:09 -0400148
149Run all of the tests like this
150
Jordan Harband9021cf52013-12-17 13:09:55 -0800151 npm test
Thomas Levinea27d3912012-10-10 19:17:09 -0400152
153Nota bene: Avoid running nvm while the tests are running.
Tim Caswell7d4b1242012-07-20 08:30:13 -0500154
Rafael Maganacfa81b42012-04-09 01:25:49 -0500155## Bash completion
156
157To activate, you need to source `bash_completion`:
158
159 [[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion
160
161Put the above sourcing line just below the sourcing line for NVM in your profile (`.bashrc`, `.bash_profile`).
162
163### Usage
164
165nvm
166
167 $ nvm [tab][tab]
Jordan Harbande7285772014-11-22 10:52:44 -0800168 alias deactivate install ls run unload
169 clear-cache exec list ls-remote unalias use
170 current help list-remote reinstall-packages uninstall version
Rafael Maganacfa81b42012-04-09 01:25:49 -0500171
172nvm alias
173
174 $ nvm alias [tab][tab]
175 default
176
177 $ nvm alias my_alias [tab][tab]
Jordan Harbande2c4c882014-05-08 10:30:18 -0700178 v0.6.21 v0.8.26 v0.10.28
Jing Dong6a98d162013-08-15 19:25:51 +0100179
Rafael Maganacfa81b42012-04-09 01:25:49 -0500180nvm use
181
182 $ nvm use [tab][tab]
Jordan Harbande2c4c882014-05-08 10:30:18 -0700183 my_alias default v0.6.21 v0.8.26 v0.10.28
Jing Dong6a98d162013-08-15 19:25:51 +0100184
Rafael Maganacfa81b42012-04-09 01:25:49 -0500185nvm uninstall
186
187 $ nvm uninstall [tab][tab]
Jordan Harbande2c4c882014-05-08 10:30:18 -0700188 my_alias default v0.6.21 v0.8.26 v0.10.28
Jordan Harband36f93392015-04-25 11:21:33 -0700189
Shane Keulen7ea15a72015-04-13 16:20:22 -0400190## Compatibility Issues
191`nvm` will encounter some issues if you have some non-default settings set. (see [#606](/../../issues/606))
192The following are known to cause issues:
193
194Inside `~/.npmrc`
195```
196prefix='some/path'
197```
198Environment Variables:
199```
200$NPM_CONFIG_PREFIX
201$PREFIX
202```
Jing Dong6a98d162013-08-15 19:25:51 +0100203
alessioalex0700d142011-11-14 15:48:56 +0200204## Problems
205
Jordan Harband9537db12013-06-14 09:13:54 -0700206If you try to install a node version and the installation fails, be sure to delete the node downloads from src (~/.nvm/src/) or you might get an error when trying to reinstall them again or you might get an error like the following:
Jing Dong6a98d162013-08-15 19:25:51 +0100207
alessioalex0700d142011-11-14 15:48:56 +0200208 curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
alessioalex629b51e2011-11-14 16:16:09 +0200209
Félix Saparelli64b16fa2015-02-08 11:05:21 +1300210Where's my 'sudo node'? Check out this link:
Jing Dong6a98d162013-08-15 19:25:51 +0100211
Tim Caswell1dbb7c72012-10-17 11:45:43 -0500212https://github.com/creationix/nvm/issues/43
elf Pavlik0dd02242012-03-07 01:34:12 +0100213
Félix Saparelli64b16fa2015-02-08 11:05:21 +1300214On Arch Linux and other systems using python3 by default, before running *install* you need to
elf Pavlik0dd02242012-03-07 01:34:12 +0100215
216 export PYTHON=python2
217
Yoshiya Hinosawa7dc08272013-01-12 13:59:28 +0900218After the v0.8.6 release of node, nvm tries to install from binary packages. But in some systems, the official binary packages don't work due to incompatibility of shared libs. In such cases, use `-s` option to force install from source:
Yoshiya Hinosawa1845a4a2013-01-12 14:40:41 +0900219
220 nvm install -s 0.8.6
Jordan Harband9537db12013-06-14 09:13:54 -0700221
Jordan Harband77f44902014-04-25 10:43:22 -0700222[1]: https://github.com/creationix/nvm.git
Jordan Harbandd78722b2015-05-29 11:11:40 -0700223[2]: https://github.com/creationix/nvm/blob/v0.25.4/install.sh
Jordan Harband77f44902014-04-25 10:43:22 -0700224[3]: https://travis-ci.org/creationix/nvm
225[Urchin]: https://github.com/scraperwiki/urchin
Félix Saparelli64b16fa2015-02-08 11:05:21 +1300226[Fish]: http://fishshell.com