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 | |
Tim Caswell | 91d2be5 | 2010-12-10 11:32:16 -0800 | [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 | |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 7 | ### Install script |
| 8 | |
Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 9 | To install you could use the [install script][2] using cURL: |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 10 | |
Michał Gołębiowski | fb5a51b | 2014-07-02 14:58:56 +0200 | [diff] [blame] | 11 | curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 12 | |
| 13 | or Wget: |
| 14 | |
Michał Gołębiowski | fb5a51b | 2014-07-02 14:58:56 +0200 | [diff] [blame] | 15 | wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash |
Koen Punt | b063b32 | 2012-12-04 23:21:00 +0100 | [diff] [blame] | 16 | |
Koen Punt | 9f62802 | 2013-12-22 18:37:08 +0100 | [diff] [blame] | 17 | <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] | 18 | |
Michał Gołębiowski | 0363687 | 2014-07-10 10:21:03 +0200 | [diff] [blame] | 19 | You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install. |
Koen Punt | 9f62802 | 2013-12-22 18:37:08 +0100 | [diff] [blame] | 20 | |
Jordan Harband | f214ffa | 2014-07-05 11:05:15 -0700 | [diff] [blame] | 21 | <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] | 22 | |
| 23 | ### Manual install |
| 24 | |
| 25 | 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] | 26 | |
| 27 | Or if you have `git` installed, then just clone it: |
| 28 | |
Fraser Tweedale | 2b216ab | 2013-08-10 10:04:25 +1000 | [diff] [blame] | 29 | git clone https://github.com/creationix/nvm.git ~/.nvm |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 30 | |
Fraser Tweedale | 5803325 | 2013-08-10 19:30:25 +1000 | [diff] [blame] | 31 | To activate nvm, you need to source it from your shell: |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 32 | |
Jordan Harband | c6cb160 | 2013-06-14 09:26:51 -0700 | [diff] [blame] | 33 | source ~/.nvm/nvm.sh |
Tim Caswell | a078d64 | 2010-12-10 11:42:19 -0800 | [diff] [blame] | 34 | |
Fraser Tweedale | 5803325 | 2013-08-10 19:30:25 +1000 | [diff] [blame] | 35 | 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] | 36 | 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] | 37 | |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 38 | ## Usage |
| 39 | |
Jordan Harband | c0c5e8d | 2014-05-04 02:20:24 -0700 | [diff] [blame] | 40 | You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory). |
| 41 | `nvm use`, `nvm install`, and `nvm run` will all respect an `.nvmrc` file. |
| 42 | |
Jordan Harband | 1e353b2 | 2013-06-14 09:14:37 -0700 | [diff] [blame] | 43 | 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] | 44 | |
Jordan Harband | 1e353b2 | 2013-06-14 09:14:37 -0700 | [diff] [blame] | 45 | nvm install 0.10 |
creationix | bb49547 | 2010-04-15 10:00:34 -0700 | [diff] [blame] | 46 | |
| 47 | And then in any new shell just use the installed version: |
| 48 | |
Jordan Harband | 1e353b2 | 2013-06-14 09:14:37 -0700 | [diff] [blame] | 49 | nvm use 0.10 |
creationix | 112f739 | 2010-04-15 10:03:42 -0700 | [diff] [blame] | 50 | |
Maciej Małecki | 335a253 | 2011-10-29 10:04:37 +0200 | [diff] [blame] | 51 | Or you can just run it: |
| 52 | |
Jordan Harband | c0c5e8d | 2014-05-04 02:20:24 -0700 | [diff] [blame] | 53 | nvm run 0.10 --version |
Maciej Małecki | 335a253 | 2011-10-29 10:04:37 +0200 | [diff] [blame] | 54 | |
Hugo Josefson | e4acd63 | 2013-03-04 12:54:42 +0100 | [diff] [blame] | 55 | If you want to see what versions are installed: |
creationix | 112f739 | 2010-04-15 10:03:42 -0700 | [diff] [blame] | 56 | |
Tim Caswell | 91d2be5 | 2010-12-10 11:32:16 -0800 | [diff] [blame] | 57 | nvm ls |
Tim Caswell | 1938f69 | 2010-05-06 18:33:46 -0500 | [diff] [blame] | 58 | |
Hugo Josefson | e4acd63 | 2013-03-04 12:54:42 +0100 | [diff] [blame] | 59 | If you want to see what versions are available to install: |
| 60 | |
| 61 | nvm ls-remote |
| 62 | |
Tim Caswell | 91d2be5 | 2010-12-10 11:32:16 -0800 | [diff] [blame] | 63 | To restore your PATH, you can deactivate it. |
| 64 | |
| 65 | nvm deactivate |
| 66 | |
Isaac Wolkerstorfer | 8617663 | 2011-01-22 19:16:24 +0100 | [diff] [blame] | 67 | To set a default Node version to be used in any new shell, use the alias 'default': |
| 68 | |
Jordan Harband | 1e353b2 | 2013-06-14 09:14:37 -0700 | [diff] [blame] | 69 | nvm alias default 0.10 |
Isaac Wolkerstorfer | 8617663 | 2011-01-22 19:16:24 +0100 | [diff] [blame] | 70 | |
Jordan Harband | ecb7a15 | 2014-01-31 10:00:19 -0800 | [diff] [blame] | 71 | 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] | 72 | |
Jordan Harband | ecb7a15 | 2014-01-31 10:00:19 -0800 | [diff] [blame] | 73 | export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist |
Kyle Kelley | 8599ea2 | 2014-01-30 19:22:44 -0800 | [diff] [blame] | 74 | nvm install 0.10 |
| 75 | |
Jordan Harband | ecb7a15 | 2014-01-31 10:00:19 -0800 | [diff] [blame] | 76 | NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist nvm install 0.10 |
| 77 | |
Tim Caswell | 7d4b124 | 2012-07-20 08:30:13 -0500 | [diff] [blame] | 78 | ## License |
| 79 | |
Jordan Harband | 1478c72 | 2013-08-20 10:39:44 -0700 | [diff] [blame] | 80 | nvm is released under the MIT license. |
Tim Caswell | 7d4b124 | 2012-07-20 08:30:13 -0500 | [diff] [blame] | 81 | |
| 82 | |
PatrickJS | 50485d6 | 2014-02-03 17:07:56 -0800 | [diff] [blame] | 83 | Copyright (C) 2010-2014 Tim Caswell |
Tim Caswell | 7d4b124 | 2012-07-20 08:30:13 -0500 | [diff] [blame] | 84 | |
| 85 | 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: |
| 86 | |
| 87 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 88 | |
| 89 | 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. |
| 90 | |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 91 | ## Running tests |
Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 92 | Tests are written in [Urchin]. Install Urchin (and other dependencies) like so: |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 93 | |
Jordan Harband | 9021cf5 | 2013-12-17 13:09:55 -0800 | [diff] [blame] | 94 | npm install |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 95 | |
| 96 | There are slow tests and fast tests. The slow tests do things like install node |
| 97 | and check that the right versions are used. The fast tests fake this to test |
| 98 | things like aliases and uninstalling. From the root of the nvm git repository, |
| 99 | run the fast tests like this. |
| 100 | |
Jordan Harband | 9021cf5 | 2013-12-17 13:09:55 -0800 | [diff] [blame] | 101 | npm run test/fast |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 102 | |
| 103 | Run the slow tests like this. |
| 104 | |
Jordan Harband | 9021cf5 | 2013-12-17 13:09:55 -0800 | [diff] [blame] | 105 | npm run test/slow |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 106 | |
| 107 | Run all of the tests like this |
| 108 | |
Jordan Harband | 9021cf5 | 2013-12-17 13:09:55 -0800 | [diff] [blame] | 109 | npm test |
Thomas Levine | a27d391 | 2012-10-10 19:17:09 -0400 | [diff] [blame] | 110 | |
| 111 | Nota bene: Avoid running nvm while the tests are running. |
Tim Caswell | 7d4b124 | 2012-07-20 08:30:13 -0500 | [diff] [blame] | 112 | |
Rafael Magana | cfa81b4 | 2012-04-09 01:25:49 -0500 | [diff] [blame] | 113 | ## Bash completion |
| 114 | |
| 115 | To activate, you need to source `bash_completion`: |
| 116 | |
| 117 | [[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion |
| 118 | |
| 119 | Put the above sourcing line just below the sourcing line for NVM in your profile (`.bashrc`, `.bash_profile`). |
| 120 | |
| 121 | ### Usage |
| 122 | |
| 123 | nvm |
| 124 | |
| 125 | $ nvm [tab][tab] |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 126 | alias copy-packages help list run uninstall version |
Rafael Magana | cfa81b4 | 2012-04-09 01:25:49 -0500 | [diff] [blame] | 127 | clear-cache deactivate install ls unalias use |
| 128 | |
| 129 | nvm alias |
| 130 | |
| 131 | $ nvm alias [tab][tab] |
| 132 | default |
| 133 | |
| 134 | $ nvm alias my_alias [tab][tab] |
Jordan Harband | e2c4c88 | 2014-05-08 10:30:18 -0700 | [diff] [blame] | 135 | v0.6.21 v0.8.26 v0.10.28 |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 136 | |
Rafael Magana | cfa81b4 | 2012-04-09 01:25:49 -0500 | [diff] [blame] | 137 | nvm use |
| 138 | |
| 139 | $ nvm use [tab][tab] |
Jordan Harband | e2c4c88 | 2014-05-08 10:30:18 -0700 | [diff] [blame] | 140 | my_alias default v0.6.21 v0.8.26 v0.10.28 |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 141 | |
Rafael Magana | cfa81b4 | 2012-04-09 01:25:49 -0500 | [diff] [blame] | 142 | nvm uninstall |
| 143 | |
| 144 | $ nvm uninstall [tab][tab] |
Jordan Harband | e2c4c88 | 2014-05-08 10:30:18 -0700 | [diff] [blame] | 145 | my_alias default v0.6.21 v0.8.26 v0.10.28 |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 146 | |
alessioalex | 0700d14 | 2011-11-14 15:48:56 +0200 | [diff] [blame] | 147 | ## Problems |
| 148 | |
Jordan Harband | 9537db1 | 2013-06-14 09:13:54 -0700 | [diff] [blame] | 149 | 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] | 150 | |
alessioalex | 0700d14 | 2011-11-14 15:48:56 +0200 | [diff] [blame] | 151 | curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume. |
alessioalex | 629b51e | 2011-11-14 16:16:09 +0200 | [diff] [blame] | 152 | |
| 153 | Where's my 'sudo node'? Checkout this link: |
Jing Dong | 6a98d16 | 2013-08-15 19:25:51 +0100 | [diff] [blame] | 154 | |
Tim Caswell | 1dbb7c7 | 2012-10-17 11:45:43 -0500 | [diff] [blame] | 155 | https://github.com/creationix/nvm/issues/43 |
elf Pavlik | 0dd0224 | 2012-03-07 01:34:12 +0100 | [diff] [blame] | 156 | |
| 157 | on Arch Linux and other systems using python3 by default, before running *install* you need to |
| 158 | |
| 159 | export PYTHON=python2 |
| 160 | |
Yoshiya Hinosawa | 7dc0827 | 2013-01-12 13:59:28 +0900 | [diff] [blame] | 161 | 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] | 162 | |
| 163 | nvm install -s 0.8.6 |
Jordan Harband | 9537db1 | 2013-06-14 09:13:54 -0700 | [diff] [blame] | 164 | |
Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 165 | [1]: https://github.com/creationix/nvm.git |
Jordan Harband | 3e5037a | 2014-06-26 17:06:45 -0700 | [diff] [blame] | 166 | [2]: https://github.com/creationix/nvm/blob/v0.10.0/install.sh |
Jordan Harband | 77f4490 | 2014-04-25 10:43:22 -0700 | [diff] [blame] | 167 | [3]: https://travis-ci.org/creationix/nvm |
| 168 | [Urchin]: https://github.com/scraperwiki/urchin |
| 169 | |