Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 1 | # Node Version Manager [][3] |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 2 | |
| 3 | ## Installation |
| 4 | |
Jordan Harband | 9d9cfdc | 2014-10-04 16:38:56 -0700 | [diff] [blame] | 5 | First 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. |
creationix | 4feb4e3 | 2010-04-15 10:06:53 -0700 | [diff] [blame] | 6 | |
Jordan Harband | 9d23f60 | 2014-10-04 16:40:15 -0700 | [diff] [blame] | 7 | Note: `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-Andrews | 896a7ed | 2015-01-18 12:05:44 -0800 | [diff] [blame] | 8 | - [nvmw](https://github.com/hakobera/nvmw) |
| 9 | - [nvm-windows](https://github.com/coreybutler/nvm-windows) |
Jordan Harband | 9d23f60 | 2014-10-04 16:40:15 -0700 | [diff] [blame] | 10 | |
Félix Saparelli | 2db71a8 | 2015-02-08 11:31:31 +1300 | [diff] [blame] | 11 | Note: `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 Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 15 | ### Install script |
| 16 | |
Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 17 | To install you could use the [install script][2] using cURL: |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 18 | |
Jordan Harband | d78722b | 2015-05-29 11:11:40 -0700 | [diff] [blame] | 19 | curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 20 | |
| 21 | or Wget: |
| 22 | |
Jordan Harband | d78722b | 2015-05-29 11:11:40 -0700 | [diff] [blame] | 23 | wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 24 | |
Koen Punt | 9f62802 | 2013-12-22 18:37:08 +0100 | [diff] [blame] | 25 | <sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub> |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 26 | |
Jordan Harband | a7b1f93 | 2014-10-19 19:28:09 -0400 | [diff] [blame] | 27 | You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR`, and `PROFILE` variables. |
| 28 | Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install. |
Koen Punt | 9f62802 | 2013-12-22 18:37:08 +0100 | [diff] [blame] | 29 | |
Jordan Harband | a7b1f93 | 2014-10-19 19:28:09 -0400 | [diff] [blame] | 30 | <sub>*NB. The installer can use `git`, `curl`, or `wget` to download `nvm`, whatever is available.*</sub> |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 31 | |
| 32 | ### Manual install |
| 33 | |
Jordan Harband | 9d9cfdc | 2014-10-04 16:38:56 -0700 | [diff] [blame] | 34 | For 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 Caswell | 6c243e5 | 2010-04-15 12:14:52 -0500 | [diff] [blame] | 35 | |
Jordan Harband | 199ba53 | 2014-09-13 00:59:09 -0700 | [diff] [blame] | 36 | Or if you have `git` installed, then just clone it, and check out the latest version: |
Tim Caswell | 6c243e5 | 2010-04-15 12:14:52 -0500 | [diff] [blame] | 37 | |
Jordan Harband | f6fef75 | 2014-09-13 11:37:19 -0700 | [diff] [blame] | 38 | git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags` |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 39 | |
Fraser Tweedale | 5803325 | 2013-08-10 19:30:25 +1000 | [diff] [blame] | 40 | To activate nvm, you need to source it from your shell: |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 41 | |
Marc-Aurèle DARCHE | 4612d8d | 2015-04-19 16:25:34 +0200 | [diff] [blame] | 42 | . ~/.nvm/nvm.sh |
Tim Caswell | a078d64 | 2010-12-10 11:42:19 -0800 | [diff] [blame] | 43 | |
Fraser Tweedale | 5803325 | 2013-08-10 19:30:25 +1000 | [diff] [blame] | 44 | I always add this line to my `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login. |
Tim Caswell | a078d64 | 2010-12-10 11:42:19 -0800 | [diff] [blame] | 45 | Often I also put in a line to use a specific version of node. |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 46 | |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 47 | ## Usage |
| 48 | |
Jordan Harband | c0c5e8d | 2014-05-04 02:20:24 -0700 | [diff] [blame] | 49 | You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory). |
Jordan Harband | f408d68 | 2014-12-17 01:30:23 -0800 | [diff] [blame] | 50 | `nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will all respect an `.nvmrc` file when a version is not supplied. |
Jordan Harband | c0c5e8d | 2014-05-04 02:20:24 -0700 | [diff] [blame] | 51 | |
Jordan Harband | 1e353b2 | 2013-06-14 09:14:37 -0700 | [diff] [blame] | 52 | To download, compile, and install the latest v0.10.x release of node, do this: |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 53 | |
Jordan Harband | 1e353b2 | 2013-06-14 09:14:37 -0700 | [diff] [blame] | 54 | nvm install 0.10 |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 55 | |
| 56 | And then in any new shell just use the installed version: |
| 57 | |
Jordan Harband | 1e353b2 | 2013-06-14 09:14:37 -0700 | [diff] [blame] | 58 | nvm use 0.10 |
creationix | 112f739 | 2010-04-15 10:03:42 -0700 | [diff] [blame] | 59 | |
Maciej Małecki | 335a253 | 2011-10-29 10:04:37 +0200 | [diff] [blame] | 60 | Or you can just run it: |
| 61 | |
Jordan Harband | c0c5e8d | 2014-05-04 02:20:24 -0700 | [diff] [blame] | 62 | nvm run 0.10 --version |
Maciej Małecki | 335a253 | 2011-10-29 10:04:37 +0200 | [diff] [blame] | 63 | |
Jordan Harband | a703d35 | 2014-08-02 19:22:53 -0700 | [diff] [blame] | 64 | Or, you can run any arbitrary command in a subshell with the desired version of node: |
Jordan Harband | d5c0e94 | 2014-08-01 01:26:33 -0700 | [diff] [blame] | 65 | |
| 66 | nvm exec 0.10 node --version |
| 67 | |
Daniel Bretoi | c9a53fe | 2014-11-21 17:55:46 -0800 | [diff] [blame] | 68 | You can also get the path to the executable to where it was installed: |
| 69 | |
| 70 | nvm which 0.10 |
| 71 | |
Jordan Harband | acfc459 | 2014-09-29 21:43:58 -0700 | [diff] [blame] | 72 | In 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 Harband | d90c1ec | 2015-01-23 02:08:13 -0800 | [diff] [blame] | 78 | |
G. Kay Lee | 3e74bac | 2015-01-25 15:29:36 +0800 | [diff] [blame] | 79 | If you want to install [io.js](https://github.com/iojs/io.js/): |
Mikeal Rogers | 0471d0f | 2015-01-20 10:21:18 -0500 | [diff] [blame] | 80 | |
| 81 | nvm install iojs |
Jordan Harband | acfc459 | 2014-09-29 21:43:58 -0700 | [diff] [blame] | 82 | |
| 83 | If 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 Josefson | e4acd63 | 2013-03-04 12:54:42 +0100 | [diff] [blame] | 88 | If you want to see what versions are installed: |
creationix | 112f739 | 2010-04-15 10:03:42 -0700 | [diff] [blame] | 89 | |
Tim Caswell | 91d2be5 | 2010-12-10 11:32:16 -0800 | [diff] [blame] | 90 | nvm ls |
Tim Caswell | 1938f69 | 2010-05-06 18:33:46 -0500 | [diff] [blame] | 91 | |
Hugo Josefson | e4acd63 | 2013-03-04 12:54:42 +0100 | [diff] [blame] | 92 | If you want to see what versions are available to install: |
| 93 | |
| 94 | nvm ls-remote |
| 95 | |
Tim Caswell | 91d2be5 | 2010-12-10 11:32:16 -0800 | [diff] [blame] | 96 | To restore your PATH, you can deactivate it. |
| 97 | |
| 98 | nvm deactivate |
| 99 | |
Isaac Wolkerstorfer | 8617663 | 2011-01-22 19:16:24 +0100 | [diff] [blame] | 100 | To set a default Node version to be used in any new shell, use the alias 'default': |
| 101 | |
Jordan Harband | acfc459 | 2014-09-29 21:43:58 -0700 | [diff] [blame] | 102 | nvm alias default stable |
Isaac Wolkerstorfer | 8617663 | 2011-01-22 19:16:24 +0100 | [diff] [blame] | 103 | |
Jordan Harband | ecb7a15 | 2014-01-31 10:00:19 -0800 | [diff] [blame] | 104 | To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`: |
Kyle Kelley | 8599ea2 | 2014-01-30 19:22:44 -0800 | [diff] [blame] | 105 | |
Jacob Hoffman-Andrews | 896a7ed | 2015-01-18 12:05:44 -0800 | [diff] [blame] | 106 | export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist |
Kyle Kelley | 8599ea2 | 2014-01-30 19:22:44 -0800 | [diff] [blame] | 107 | nvm install 0.10 |
| 108 | |
Jacob Hoffman-Andrews | 896a7ed | 2015-01-18 12:05:44 -0800 | [diff] [blame] | 109 | NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 0.10 |
Jordan Harband | ecb7a15 | 2014-01-31 10:00:19 -0800 | [diff] [blame] | 110 | |
yelo | c8f712a | 2015-01-23 11:18:51 +0800 | [diff] [blame] | 111 | To 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 Harband | ca89cce | 2014-10-14 17:38:42 -0700 | [diff] [blame] | 118 | `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 Harband | a00a3a7 | 2014-09-03 00:07:45 -0700 | [diff] [blame] | 119 | |
Tim Caswell | 7d4b124 | 2012-07-20 08:30:13 -0500 | [diff] [blame] | 120 | ## License |
| 121 | |
Jordan Harband | 1478c72 | 2013-08-20 10:39:44 -0700 | [diff] [blame] | 122 | nvm is released under the MIT license. |
Tim Caswell | 7d4b124 | 2012-07-20 08:30:13 -0500 | [diff] [blame] | 123 | |
| 124 | |
PatrickJS | 50485d6 | 2014-02-03 17:07:56 -0800 | [diff] [blame] | 125 | Copyright (C) 2010-2014 Tim Caswell |
Tim Caswell | 7d4b124 | 2012-07-20 08:30:13 -0500 | [diff] [blame] | 126 | |
| 127 | Permission 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 | |
| 129 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 130 | |
| 131 | THE 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 Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 133 | ## Running tests |
Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 134 | Tests are written in [Urchin]. Install Urchin (and other dependencies) like so: |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 135 | |
Jordan Harband | 9021cf5 | 2013-12-17 13:09:55 -0800 | [diff] [blame] | 136 | npm install |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 137 | |
| 138 | There are slow tests and fast tests. The slow tests do things like install node |
| 139 | and check that the right versions are used. The fast tests fake this to test |
| 140 | things like aliases and uninstalling. From the root of the nvm git repository, |
| 141 | run the fast tests like this. |
| 142 | |
Jordan Harband | 9021cf5 | 2013-12-17 13:09:55 -0800 | [diff] [blame] | 143 | npm run test/fast |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 144 | |
| 145 | Run the slow tests like this. |
| 146 | |
Jordan Harband | 9021cf5 | 2013-12-17 13:09:55 -0800 | [diff] [blame] | 147 | npm run test/slow |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 148 | |
| 149 | Run all of the tests like this |
| 150 | |
Jordan Harband | 9021cf5 | 2013-12-17 13:09:55 -0800 | [diff] [blame] | 151 | npm test |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 152 | |
| 153 | Nota bene: Avoid running nvm while the tests are running. |
Tim Caswell | 7d4b124 | 2012-07-20 08:30:13 -0500 | [diff] [blame] | 154 | |
Rafael Magana | cfa81b4 | 2012-04-09 01:25:49 -0500 | [diff] [blame] | 155 | ## Bash completion |
| 156 | |
| 157 | To activate, you need to source `bash_completion`: |
| 158 | |
| 159 | [[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion |
| 160 | |
| 161 | Put the above sourcing line just below the sourcing line for NVM in your profile (`.bashrc`, `.bash_profile`). |
| 162 | |
| 163 | ### Usage |
| 164 | |
| 165 | nvm |
| 166 | |
| 167 | $ nvm [tab][tab] |
Jordan Harband | e728577 | 2014-11-22 10:52:44 -0800 | [diff] [blame] | 168 | 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 Magana | cfa81b4 | 2012-04-09 01:25:49 -0500 | [diff] [blame] | 171 | |
| 172 | nvm alias |
| 173 | |
| 174 | $ nvm alias [tab][tab] |
| 175 | default |
| 176 | |
| 177 | $ nvm alias my_alias [tab][tab] |
Jordan Harband | e2c4c88 | 2014-05-08 10:30:18 -0700 | [diff] [blame] | 178 | v0.6.21 v0.8.26 v0.10.28 |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 179 | |
Rafael Magana | cfa81b4 | 2012-04-09 01:25:49 -0500 | [diff] [blame] | 180 | nvm use |
| 181 | |
| 182 | $ nvm use [tab][tab] |
Jordan Harband | e2c4c88 | 2014-05-08 10:30:18 -0700 | [diff] [blame] | 183 | my_alias default v0.6.21 v0.8.26 v0.10.28 |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 184 | |
Rafael Magana | cfa81b4 | 2012-04-09 01:25:49 -0500 | [diff] [blame] | 185 | nvm uninstall |
| 186 | |
| 187 | $ nvm uninstall [tab][tab] |
Jordan Harband | e2c4c88 | 2014-05-08 10:30:18 -0700 | [diff] [blame] | 188 | my_alias default v0.6.21 v0.8.26 v0.10.28 |
Jordan Harband | 36f9339 | 2015-04-25 11:21:33 -0700 | [diff] [blame] | 189 | |
Shane Keulen | 7ea15a7 | 2015-04-13 16:20:22 -0400 | [diff] [blame] | 190 | ## Compatibility Issues |
| 191 | `nvm` will encounter some issues if you have some non-default settings set. (see [#606](/../../issues/606)) |
| 192 | The following are known to cause issues: |
| 193 | |
| 194 | Inside `~/.npmrc` |
| 195 | ``` |
| 196 | prefix='some/path' |
| 197 | ``` |
| 198 | Environment Variables: |
| 199 | ``` |
| 200 | $NPM_CONFIG_PREFIX |
| 201 | $PREFIX |
| 202 | ``` |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 203 | |
alessioalex | 0700d14 | 2011-11-14 15:48:56 +0200 | [diff] [blame] | 204 | ## Problems |
| 205 | |
Jordan Harband | 9537db1 | 2013-06-14 09:13:54 -0700 | [diff] [blame] | 206 | If 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 Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 207 | |
alessioalex | 0700d14 | 2011-11-14 15:48:56 +0200 | [diff] [blame] | 208 | curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume. |
alessioalex | 629b51e | 2011-11-14 16:16:09 +0200 | [diff] [blame] | 209 | |
Félix Saparelli | 64b16fa | 2015-02-08 11:05:21 +1300 | [diff] [blame] | 210 | Where's my 'sudo node'? Check out this link: |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 211 | |
Tim Caswell | 1dbb7c7 | 2012-10-17 11:45:43 -0500 | [diff] [blame] | 212 | https://github.com/creationix/nvm/issues/43 |
elf Pavlik | 0dd0224 | 2012-03-07 01:34:12 +0100 | [diff] [blame] | 213 | |
Félix Saparelli | 64b16fa | 2015-02-08 11:05:21 +1300 | [diff] [blame] | 214 | On Arch Linux and other systems using python3 by default, before running *install* you need to |
elf Pavlik | 0dd0224 | 2012-03-07 01:34:12 +0100 | [diff] [blame] | 215 | |
| 216 | export PYTHON=python2 |
| 217 | |
Yoshiya Hinosawa | 7dc0827 | 2013-01-12 13:59:28 +0900 | [diff] [blame] | 218 | After 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 Hinosawa | 1845a4a | 2013-01-12 14:40:41 +0900 | [diff] [blame] | 219 | |
| 220 | nvm install -s 0.8.6 |
Jordan Harband | 9537db1 | 2013-06-14 09:13:54 -0700 | [diff] [blame] | 221 | |
Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 222 | [1]: https://github.com/creationix/nvm.git |
Jordan Harband | d78722b | 2015-05-29 11:11:40 -0700 | [diff] [blame] | 223 | [2]: https://github.com/creationix/nvm/blob/v0.25.4/install.sh |
Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 224 | [3]: https://travis-ci.org/creationix/nvm |
| 225 | [Urchin]: https://github.com/scraperwiki/urchin |
Félix Saparelli | 64b16fa | 2015-02-08 11:05:21 +1300 | [diff] [blame] | 226 | [Fish]: http://fishshell.com |