diff --git a/README.markdown b/README.markdown index 09c4d1d..8b6a300 100644 --- a/README.markdown +++ b/README.markdown @@ -27,6 +27,10 @@ And then in any new shell just use the installed version: nvm use v0.4.1 +Or you can just run it: + + nvm run v0.4.1 + If you want to see what versions are available: nvm ls @@ -39,3 +43,12 @@ To set a default Node version to be used in any new shell, use the alias 'defaul nvm alias default v0.4.1 +## Problems + +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: + + curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume. + +Where's my 'sudo node'? Checkout this link: + + https://github.com/creationix/nvm/issues/43 diff --git a/nvm.sh b/nvm.sh index d8ff132..b72bd0d 100755 --- a/nvm.sh +++ b/nvm.sh @@ -88,6 +88,7 @@ nvm() echo " nvm install Download and install a " echo " nvm uninstall Uninstall a version" echo " nvm use Modify PATH to use " + echo " nvm run [] Run with as arguments" echo " nvm ls List installed versions" echo " nvm ls List versions matching a given description" echo " nvm deactivate Undo effects of NVM on current shell" @@ -99,6 +100,7 @@ nvm() echo "Example:" echo " nvm install v0.4.12 Install a specific version number" echo " nvm use 0.2 Use the latest available 0.2.x release" + echo " nvm run 0.4.12 myApp.js Run myApp.js using node v0.4.12" echo " nvm alias default 0.4 Auto use the latest installed v0.4.x version" echo ;; @@ -134,8 +136,17 @@ nvm() nvm use $VERSION if ! which npm ; then echo "Installing npm..." - # TODO: if node version 0.2.x add npm_install=0.2.19 before sh - curl http://npmjs.org/install.sh | clean=yes sh + if [[ "`expr match $VERSION '\(^v0\.1\.\)'`" != '' ]]; then + echo "npm requires node v0.2.3 or higher" + elif [[ "`expr match $VERSION '\(^v0\.2\.\)'`" != '' ]]; then + if [[ "`expr match $VERSION '\(^v0\.2\.[0-2]$\)'`" != '' ]]; then + echo "npm requires node v0.2.3 or higher" + else + curl http://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh + fi + else + curl http://npmjs.org/install.sh | clean=yes sh + fi fi else echo "nvm: install $VERSION failed!" @@ -210,6 +221,20 @@ nvm() export NVM_BIN="$NVM_DIR/$VERSION/bin" echo "Now using node $VERSION" ;; + "run" ) + # run given version of node + if [ $# -lt 2 ]; then + nvm help + return + fi + VERSION=`nvm_version $2` + if [ ! -d $NVM_DIR/$VERSION ]; then + echo "$VERSION version is not installed yet" + return; + fi + echo "Running node $VERSION" + $NVM_DIR/$VERSION/bin/node "${@:3}" + ;; "ls" | "list" ) print_versions "`nvm_ls $2`" if [ $# -eq 1 ]; then