| 1 |
Node.js virtual environment |
| 2 |
=========================== |
| 3 |
|
| 4 |
``nodeenv`` (node.js virtual environment) is a tool to create |
| 5 |
isolated node.js environments. |
| 6 |
|
| 7 |
It creates an environment that has its own installation directories, |
| 8 |
that doesn't share libraries with other node.js virtual environments. |
| 9 |
|
| 10 |
Also the new environment can be integrated with the environment which was built |
| 11 |
by virtualenv_ (python). |
| 12 |
|
| 13 |
If you use nodeenv feel free to add your project on wiki: `Who-Uses-Nodeenv`_. |
| 14 |
|
| 15 |
.. _Who-Uses-Nodeenv: https://github.com/ekalinin/nodeenv/wiki/Who-Uses-Nodeenv |
| 16 |
|
| 17 |
.. image:: https://travis-ci.org/ekalinin/nodeenv.svg?branch=master |
| 18 |
:target: https://travis-ci.org/ekalinin/nodeenv |
| 19 |
|
| 20 |
.. contents:: :local: |
| 21 |
|
| 22 |
|
| 23 |
Install |
| 24 |
------- |
| 25 |
|
| 26 |
Global installation |
| 27 |
^^^^^^^^^^^^^^^^^^^ |
| 28 |
|
| 29 |
You can install nodeenv globally with `easy_install`_:: |
| 30 |
|
| 31 |
$ sudo easy_install nodeenv |
| 32 |
|
| 33 |
or with `pip`_:: |
| 34 |
|
| 35 |
$ sudo pip install nodeenv |
| 36 |
|
| 37 |
or on Debian using `dpkg`_:: |
| 38 |
|
| 39 |
$ ln -s debian-upstream debian |
| 40 |
$ dpkg-buildpackage -uc -us -b |
| 41 |
$ sudo dpkg -i $(ls -1rt ../nodeenv_*.deb | tail -n1) |
| 42 |
|
| 43 |
.. _dpkg: https://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html |
| 44 |
|
| 45 |
Local installation |
| 46 |
^^^^^^^^^^^^^^^^^^ |
| 47 |
|
| 48 |
If you're using virtualenv_ then you can install nodeenv via |
| 49 |
pip_/easy_install_ inside any virtual environment built with virtualenv:: |
| 50 |
|
| 51 |
$ virtualenv env |
| 52 |
$ . env/bin/activate |
| 53 |
(env) $ pip install nodeenv |
| 54 |
(env) $ nodeenv --version |
| 55 |
0.6.5 |
| 56 |
|
| 57 |
If you want to work with the latest version of the nodeenv you can |
| 58 |
install it from the github `repository`_:: |
| 59 |
|
| 60 |
$ git clone https://github.com/ekalinin/nodeenv.git |
| 61 |
$ ./nodeenv/nodeenv.py --help |
| 62 |
|
| 63 |
or with `pip`_:: |
| 64 |
|
| 65 |
$ pip install -e git+https://github.com/ekalinin/nodeenv.git#egg=nodeenv |
| 66 |
|
| 67 |
.. _repository: https://github.com/ekalinin/nodeenv |
| 68 |
.. _pip: http://pypi.python.org/pypi/pip |
| 69 |
.. _easy_install: http://pypi.python.org/pypi/setuptools |
| 70 |
|
| 71 |
|
| 72 |
Dependency |
| 73 |
---------- |
| 74 |
|
| 75 |
For nodeenv |
| 76 |
^^^^^^^^^^^ |
| 77 |
|
| 78 |
* python (2.6+, 3.5+, or pypy) |
| 79 |
* make |
| 80 |
* tail |
| 81 |
|
| 82 |
For node.js |
| 83 |
^^^^^^^^^^^ |
| 84 |
|
| 85 |
* libssl-dev |
| 86 |
|
| 87 |
Usage |
| 88 |
----- |
| 89 |
|
| 90 |
Basic |
| 91 |
^^^^^ |
| 92 |
|
| 93 |
Create new environment:: |
| 94 |
|
| 95 |
$ nodeenv env |
| 96 |
|
| 97 |
Activate new environment:: |
| 98 |
|
| 99 |
$ . env/bin/activate |
| 100 |
|
| 101 |
Check versions of main packages:: |
| 102 |
|
| 103 |
(env) $ node -v |
| 104 |
v0.10.26 |
| 105 |
|
| 106 |
(env) $ npm -v |
| 107 |
1.4.3 |
| 108 |
|
| 109 |
Deactivate environment:: |
| 110 |
|
| 111 |
(env) $ deactivate_node |
| 112 |
|
| 113 |
Advanced |
| 114 |
^^^^^^^^ |
| 115 |
|
| 116 |
Get available node.js versions:: |
| 117 |
|
| 118 |
$ nodeenv --list |
| 119 |
0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.1.0 |
| 120 |
0.1.2 0.1.3 0.1.4 0.1.5 0.1.6 0.1.7 0.1.8 |
| 121 |
0.1.10 0.1.11 0.1.12 0.1.13 0.1.14 0.1.15 0.1.16 |
| 122 |
0.1.18 0.1.19 0.1.20 0.1.21 0.1.22 0.1.23 0.1.24 |
| 123 |
0.1.26 0.1.27 0.1.28 0.1.29 0.1.30 0.1.31 0.1.32 |
| 124 |
0.1.90 0.1.91 0.1.92 0.1.93 0.1.94 0.1.95 0.1.96 |
| 125 |
0.1.98 0.1.99 0.1.100 0.1.101 0.1.102 0.1.103 0.1.104 |
| 126 |
0.2.1 0.2.2 0.2.3 0.2.4 0.2.5 0.2.6 0.3.0 |
| 127 |
0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 0.3.8 |
| 128 |
0.4.1 0.4.2 0.4.3 0.4.4 0.4.5 0.4.6 |
| 129 |
|
| 130 |
Install node.js "0.4.3" without ssl support with 4 parallel commands |
| 131 |
for compilation and npm.js "0.3.17":: |
| 132 |
|
| 133 |
$ nodeenv --without-ssl --node=0.4.3 --npm=0.3.17 --with-npm --jobs=4 env-4.3 |
| 134 |
|
| 135 |
Install node.js from the source:: |
| 136 |
|
| 137 |
$ nodeenv --node=0.10.25 --source env-0.10.25 |
| 138 |
|
| 139 |
Install node.js from a mirror:: |
| 140 |
|
| 141 |
$ nodeenv --node=10.19.0 --mirror=https://npm.taobao.org/mirrors/node |
| 142 |
|
| 143 |
It's much faster to install from the prebuilt package than Install & compile |
| 144 |
node.js from source:: |
| 145 |
|
| 146 |
$ time nodeenv --node=0.10.25 --prebuilt env-0.10.25-prebuilt |
| 147 |
+ Install node.js (0.10.25) ... done. |
| 148 |
|
| 149 |
real 0m6.928s |
| 150 |
user 0m0.408s |
| 151 |
sys 0m1.144s |
| 152 |
|
| 153 |
$ time nodeenv --node=0.10.25 --source env-0.10.25-src |
| 154 |
+ Install node.js (0.10.25) ... done. |
| 155 |
|
| 156 |
real 4m12.602s |
| 157 |
user 6m34.112s |
| 158 |
sys 0m30.524s |
| 159 |
|
| 160 |
Create a new environment with the system-wide node.js:: |
| 161 |
|
| 162 |
$ nodeenv --node=system |
| 163 |
|
| 164 |
Saving the versions of all installed packages to a file:: |
| 165 |
|
| 166 |
$ . env-4.3/bin/activate |
| 167 |
(env-4.3)$ npm install -g express |
| 168 |
(env-4.3)$ npm install -g jade |
| 169 |
(env-4.3)$ freeze ../prod-requirements.txt |
| 170 |
|
| 171 |
If you want to list locally installed packages use ``-l`` option:: |
| 172 |
|
| 173 |
(env-4.3)$ freeze -l ../prod-requirements.txt |
| 174 |
|
| 175 |
Create an environment from a requirements file:: |
| 176 |
|
| 177 |
$ nodeenv --requirements=../prod-requirements.txt --jobs=4 env-copy |
| 178 |
|
| 179 |
Requirements files are plain text files that contain a list of packages |
| 180 |
to be installed. These text files allow you to create repeatable installations. |
| 181 |
Requirements file example:: |
| 182 |
|
| 183 |
$ cat ../prod-requirements.txt |
| 184 |
[email protected] |
| 185 |
[email protected] |
| 186 |
[email protected] |
| 187 |
[email protected] |
| 188 |
[email protected] |
| 189 |
[email protected] |
| 190 |
|
| 191 |
If you already have the python virtualenv tool, and want to use nodeenv and |
| 192 |
virtualenv in conjunction, then you should create (or activate) the python |
| 193 |
virtual environment:: |
| 194 |
|
| 195 |
# in case of using virtualenv_wrapper |
| 196 |
$ mkvirtualenv my_env |
| 197 |
|
| 198 |
# in case of using virtualenv |
| 199 |
$ . my_env/bin/activate |
| 200 |
|
| 201 |
and add a node virtual environment to this existing new_venv:: |
| 202 |
|
| 203 |
$ nodeenv -p |
| 204 |
|
| 205 |
If you need to set the path to make used to build node:: |
| 206 |
|
| 207 |
$ nodeenv -m /usr/local/bin/gmake ENV |
| 208 |
|
| 209 |
That's all. Now, all your node.js modules will be installed into your virtual |
| 210 |
environment:: |
| 211 |
|
| 212 |
$ workon my_env |
| 213 |
$ npm install -g coffee-script |
| 214 |
$ command -v coffee |
| 215 |
/home/monty/virtualenvs/my_env/bin/coffee |
| 216 |
|
| 217 |
Creating a virtual environment with a custom prompt: |
| 218 |
|
| 219 |
$ nodeenv --node=12.18.2 --prompt="(myenv)" nodeenv |
| 220 |
|
| 221 |
If environment's directory already exists then you can use ``--force`` option:: |
| 222 |
|
| 223 |
$ nodeenv --requirements=requirements.txt --jobs=4 --force env |
| 224 |
|
| 225 |
If you already have an environment and want to update packages from requirements |
| 226 |
file you can use ``--update`` option:: |
| 227 |
|
| 228 |
$ . env-4.3/bin/activate |
| 229 |
(env-4.3)$ nodeenv --requirements=requirements.txt --update env-4.3 |
| 230 |
|
| 231 |
If you want to call node from environment without activation then you should |
| 232 |
use `shim` script:: |
| 233 |
|
| 234 |
$ ./env-4.3/bin/shim --version |
| 235 |
v0.4.3 |
| 236 |
|
| 237 |
Configuration |
| 238 |
------------- |
| 239 |
You can use the INI-style file ``~/.nodeenvrc`` to set default values for many options, |
| 240 |
the keys in that file are the long command-line option names. |
| 241 |
|
| 242 |
These are the available options and their defaults:: |
| 243 |
|
| 244 |
[nodeenv] |
| 245 |
node = 'latest' |
| 246 |
npm = 'latest' |
| 247 |
with_npm = False |
| 248 |
jobs = '2' |
| 249 |
without_ssl = False |
| 250 |
debug = False |
| 251 |
profile = False |
| 252 |
make = 'make' |
| 253 |
prebuilt = True |
| 254 |
ignore_ssl_certs = False |
| 255 |
mirror = None |
| 256 |
|
| 257 |
Alternatives |
| 258 |
------------ |
| 259 |
|
| 260 |
There are several alternatives that create isolated environments: |
| 261 |
|
| 262 |
* `nave <https://github.com/isaacs/nave>`_ - Virtual Environments for Node. |
| 263 |
Nave stores all environments in one directory ``~/.nave``. Can create |
| 264 |
per node version environments using `nave use envname versionname`. |
| 265 |
Can not pass additional arguments into configure (for example --without-ssl) |
| 266 |
Can't run on windows because it relies on bash. |
| 267 |
|
| 268 |
* `nvm <https://github.com/creationix/nvm/blob/master/nvm.sh>`_ - Node Version |
| 269 |
Manager. It is necessarily to do `nvm sync` for caching available node.js |
| 270 |
version. |
| 271 |
Can not pass additional arguments into configure (for example --without-ssl) |
| 272 |
|
| 273 |
* virtualenv_ - Virtual Python Environment builder. For python only. |
| 274 |
|
| 275 |
.. _`virtualenv`: https://github.com/pypa/virtualenv |
| 276 |
|
| 277 |
LICENSE |
| 278 |
======= |
| 279 |
|
| 280 |
BSD / `LICENSE <https://github.com/ekalinin/nodeenv/blob/master/LICENSE>`_ |