blob: 25888d39952ab7991477b34fe7d3be126a430d21 [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
Tim Caswell91d2be52010-12-10 11:32:16 -08005First 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
Koen Puntb063b322012-12-04 23:21:00 +01007### Install script
8
Jordan Harband77f44902014-04-25 10:43:22 -07009To install you could use the [install script][2] using cURL:
Koen Puntb063b322012-12-04 23:21:00 +010010
Michał Gołębiowskifb5a51b2014-07-02 14:58:56 +020011 curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash
Koen Puntb063b322012-12-04 23:21:00 +010012
13or Wget:
14
Michał Gołębiowskifb5a51b2014-07-02 14:58:56 +020015 wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash
Koen Puntb063b322012-12-04 23:21:00 +010016
Koen Punt9f628022013-12-22 18:37:08 +010017<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 +010018
Michał Gołębiowski03636872014-07-10 10:21:03 +020019You 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 Punt9f628022013-12-22 18:37:08 +010020
Jordan Harbandf214ffa2014-07-05 11:05:15 -070021<sub>*NB. The installer can use Git, curl, or wget to download NVM, whatever is available.*</sub>
Koen Puntb063b322012-12-04 23:21:00 +010022
23### Manual install
24
25For 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 -050026
27Or if you have `git` installed, then just clone it:
28
Fraser Tweedale2b216ab2013-08-10 10:04:25 +100029 git clone https://github.com/creationix/nvm.git ~/.nvm
creationixbb495472010-04-15 10:00:34 -070030
Fraser Tweedale58033252013-08-10 19:30:25 +100031To activate nvm, you need to source it from your shell:
creationixbb495472010-04-15 10:00:34 -070032
Jordan Harbandc6cb1602013-06-14 09:26:51 -070033 source ~/.nvm/nvm.sh
Tim Caswella078d642010-12-10 11:42:19 -080034
Fraser Tweedale58033252013-08-10 19:30:25 +100035I 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 -080036Often I also put in a line to use a specific version of node.
Jing Dong6a98d162013-08-15 19:25:51 +010037
creationixbb495472010-04-15 10:00:34 -070038## Usage
39
Jordan Harbandc0c5e8d2014-05-04 02:20:24 -070040You 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 Harband1e353b22013-06-14 09:14:37 -070043To download, compile, and install the latest v0.10.x release of node, do this:
creationixbb495472010-04-15 10:00:34 -070044
Jordan Harband1e353b22013-06-14 09:14:37 -070045 nvm install 0.10
creationixbb495472010-04-15 10:00:34 -070046
47And then in any new shell just use the installed version:
48
Jordan Harband1e353b22013-06-14 09:14:37 -070049 nvm use 0.10
creationix112f7392010-04-15 10:03:42 -070050
Maciej Małecki335a2532011-10-29 10:04:37 +020051Or you can just run it:
52
Jordan Harbandc0c5e8d2014-05-04 02:20:24 -070053 nvm run 0.10 --version
Maciej Małecki335a2532011-10-29 10:04:37 +020054
Hugo Josefsone4acd632013-03-04 12:54:42 +010055If you want to see what versions are installed:
creationix112f7392010-04-15 10:03:42 -070056
Tim Caswell91d2be52010-12-10 11:32:16 -080057 nvm ls
Tim Caswell1938f692010-05-06 18:33:46 -050058
Hugo Josefsone4acd632013-03-04 12:54:42 +010059If you want to see what versions are available to install:
60
61 nvm ls-remote
62
Tim Caswell91d2be52010-12-10 11:32:16 -080063To restore your PATH, you can deactivate it.
64
65 nvm deactivate
66
Isaac Wolkerstorfer86176632011-01-22 19:16:24 +010067To set a default Node version to be used in any new shell, use the alias 'default':
68
Jordan Harband1e353b22013-06-14 09:14:37 -070069 nvm alias default 0.10
Isaac Wolkerstorfer86176632011-01-22 19:16:24 +010070
Jordan Harbandecb7a152014-01-31 10:00:19 -080071To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
Kyle Kelley8599ea22014-01-30 19:22:44 -080072
Jordan Harbandecb7a152014-01-31 10:00:19 -080073 export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
Kyle Kelley8599ea22014-01-30 19:22:44 -080074 nvm install 0.10
75
Jordan Harbandecb7a152014-01-31 10:00:19 -080076 NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist nvm install 0.10
77
Tim Caswell7d4b1242012-07-20 08:30:13 -050078## License
79
Jordan Harband1478c722013-08-20 10:39:44 -070080nvm is released under the MIT license.
Tim Caswell7d4b1242012-07-20 08:30:13 -050081
82
PatrickJS50485d62014-02-03 17:07:56 -080083Copyright (C) 2010-2014 Tim Caswell
Tim Caswell7d4b1242012-07-20 08:30:13 -050084
85Permission 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
87The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
88
89THE 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 Levinea27d3912012-10-10 19:17:09 -040091## Running tests
Jordan Harband77f44902014-04-25 10:43:22 -070092Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
Thomas Levinea27d3912012-10-10 19:17:09 -040093
Jordan Harband9021cf52013-12-17 13:09:55 -080094 npm install
Thomas Levinea27d3912012-10-10 19:17:09 -040095
96There are slow tests and fast tests. The slow tests do things like install node
97and check that the right versions are used. The fast tests fake this to test
98things like aliases and uninstalling. From the root of the nvm git repository,
99run the fast tests like this.
100
Jordan Harband9021cf52013-12-17 13:09:55 -0800101 npm run test/fast
Thomas Levinea27d3912012-10-10 19:17:09 -0400102
103Run the slow tests like this.
104
Jordan Harband9021cf52013-12-17 13:09:55 -0800105 npm run test/slow
Thomas Levinea27d3912012-10-10 19:17:09 -0400106
107Run all of the tests like this
108
Jordan Harband9021cf52013-12-17 13:09:55 -0800109 npm test
Thomas Levinea27d3912012-10-10 19:17:09 -0400110
111Nota bene: Avoid running nvm while the tests are running.
Tim Caswell7d4b1242012-07-20 08:30:13 -0500112
Rafael Maganacfa81b42012-04-09 01:25:49 -0500113## Bash completion
114
115To activate, you need to source `bash_completion`:
116
117 [[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion
118
119Put the above sourcing line just below the sourcing line for NVM in your profile (`.bashrc`, `.bash_profile`).
120
121### Usage
122
123nvm
124
125 $ nvm [tab][tab]
Jing Dong6a98d162013-08-15 19:25:51 +0100126 alias copy-packages help list run uninstall version
Rafael Maganacfa81b42012-04-09 01:25:49 -0500127 clear-cache deactivate install ls unalias use
128
129nvm alias
130
131 $ nvm alias [tab][tab]
132 default
133
134 $ nvm alias my_alias [tab][tab]
Jordan Harbande2c4c882014-05-08 10:30:18 -0700135 v0.6.21 v0.8.26 v0.10.28
Jing Dong6a98d162013-08-15 19:25:51 +0100136
Rafael Maganacfa81b42012-04-09 01:25:49 -0500137nvm use
138
139 $ nvm use [tab][tab]
Jordan Harbande2c4c882014-05-08 10:30:18 -0700140 my_alias default v0.6.21 v0.8.26 v0.10.28
Jing Dong6a98d162013-08-15 19:25:51 +0100141
Rafael Maganacfa81b42012-04-09 01:25:49 -0500142nvm uninstall
143
144 $ nvm uninstall [tab][tab]
Jordan Harbande2c4c882014-05-08 10:30:18 -0700145 my_alias default v0.6.21 v0.8.26 v0.10.28
Jing Dong6a98d162013-08-15 19:25:51 +0100146
alessioalex0700d142011-11-14 15:48:56 +0200147## Problems
148
Jordan Harband9537db12013-06-14 09:13:54 -0700149If 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 +0100150
alessioalex0700d142011-11-14 15:48:56 +0200151 curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
alessioalex629b51e2011-11-14 16:16:09 +0200152
153Where's my 'sudo node'? Checkout this link:
Jing Dong6a98d162013-08-15 19:25:51 +0100154
Tim Caswell1dbb7c72012-10-17 11:45:43 -0500155https://github.com/creationix/nvm/issues/43
elf Pavlik0dd02242012-03-07 01:34:12 +0100156
157on Arch Linux and other systems using python3 by default, before running *install* you need to
158
159 export PYTHON=python2
160
Yoshiya Hinosawa7dc08272013-01-12 13:59:28 +0900161After 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 +0900162
163 nvm install -s 0.8.6
Jordan Harband9537db12013-06-14 09:13:54 -0700164
Jordan Harband77f44902014-04-25 10:43:22 -0700165[1]: https://github.com/creationix/nvm.git
Jordan Harband3e5037a2014-06-26 17:06:45 -0700166[2]: https://github.com/creationix/nvm/blob/v0.10.0/install.sh
Jordan Harband77f44902014-04-25 10:43:22 -0700167[3]: https://travis-ci.org/creationix/nvm
168[Urchin]: https://github.com/scraperwiki/urchin
169