Trim and update nvm

master
Tim Caswell 2010-12-10 11:32:16 -08:00 committed by isaacs
parent 9ef89f51c9
commit dd32e5880d
2 changed files with 26 additions and 75 deletions

View File

@ -2,7 +2,7 @@
## Installation
First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential package works. You'll also need `git` if you want to track HEAD.
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.
To install create a folder somewhere in your filesystem with the "`nvm.sh`" file inside it. I put mine in a folder called "`.nvm`".
@ -10,38 +10,25 @@ Or if you have `git` installed, then just clone it:
git clone git://github.com/creationix/nvm.git ~/.nvm
Then add two lines to your bash profile:
NVM_DIR=$HOME/.nvm
. $NVM_DIR/nvm.sh
nvm use
The first line loads the `nvm` function into your bash shell so that it's available as a command. The second line sets your default node version to the latest released version.
To activate nvm, you need to source it from your bash shell
. ~/.nvm/nvm.sh
## Usage
To download, install, and use the v0.1.94 release of node do this:
To download, install, and use the v0.2.5 release of node do this:
nvm install v0.1.94
nvm install v0.2.5
And then in any new shell just use the installed version:
nvm use v0.1.94
If you want to track HEAD then use the clone command:
nvm clone
Then in any new shell you can get this version with:
nvm use HEAD
When you want to grab the latest from the node repo do:
nvm update
nvm use v0.2.5
If you want to see what versions you have installed issue:
nvm list
nvm ls
To restore your PATH, you can deactivate it.
nvm deactivate
If you want to install nvm to somewhere other than `$HOME/.nvm`, then set the `$NVM_DIR` environment variable before sourcing the nvm.sh file.

64
nvm.sh
View File

@ -5,6 +5,9 @@
# Implemented by Tim Caswell <tim@creationix.com>
# with much bash help from Matthew Ranney
# Auto detect the NVM_DIR using magic bash 3.x stuff
export NVM_DIR=$(dirname ${BASH_ARGV[0]})
nvm()
{
START=`pwd`
@ -18,18 +21,15 @@ nvm()
echo "Node Version Manager"
echo
echo "Usage:"
echo " nvm help (Show this message)"
echo " nvm install version (Download and install a released version)"
echo " nvm list (Show all installed versions)"
echo " nvm use version (Set this version in the PATH)"
echo " nvm use (Use the latest stable version)"
echo " nvm deactivate (Remove nvm entry from PATH)"
echo " nvm addlib (Copies the module in cwd to the current env)"
echo " nvm linklib (Links the module in cwd to the current env)"
echo " nvm listlibs (Show the modules in the current env)"
echo " nvm help Show this message"
echo " nvm install <version> Download and install a <version>"
echo " nvm use <version> Modify PATH to use <version>"
echo " nvm ls List versions currently installed"
echo " nvm deactivate Undo effects of NVM on current shell"
echo
echo "Example:"
echo " nvm install v0.1.94"
echo " nvm install v0.2.5"
echo " nvm use v0.2.5"
echo
;;
"install" )
@ -55,37 +55,11 @@ nvm()
else
echo "Could not find $NVM_DIR/*/bin in \$PATH"
fi
unset NVM_PATH
unset NVM_DIR
unset NVM_BIN
echo "Unset NVM_PATH, NVM_BIN, and NVM_DIR."
;;
"addlib" )
mkdir -p $NVM_PATH
mkdir -p $NVM_BIN
if [ -d `pwd`/lib ]; then
cp -r `pwd`/lib/ "$NVM_PATH/"
cp -r `pwd`/bin/ "$NVM_BIN/"
else
echo "Can't find lib dir at `pwd`/lib"
fi
;;
"linklib" )
mkdir -p $NVM_PATH
mkdir -p $NVM_BIN
if [ -d `pwd`/lib ]; then
ln -sf `pwd`/lib/* "$NVM_PATH/"
ln -sf `pwd`/bin/* "$NVM_BIN/"
else
echo "Can't find lib dir at `pwd`/lib"
fi
;;
"use" )
if [ $# -ne 2 ]; then
for f in $NVM_DIR/v*; do
nvm use ${f##*/} > /dev/null
done
return;
nvm help
return
fi
if [ ! -d $NVM_DIR/$2 ]; then
echo "$2 version is not installed yet"
@ -101,21 +75,11 @@ nvm()
export NVM_BIN="$NVM_DIR/$2/bin"
echo "Now using node $2"
;;
"listlibs" )
ls $NVM_PATH | grep -v wafadmin
;;
"list" )
"ls" )
if [ $# -ne 1 ]; then
nvm help
return;
fi
if [ -d $NVM_DIR/HEAD ]; then
if [[ $PATH == *$NVM_DIR/HEAD/bin* ]]; then
echo "HEAD *"
else
echo "HEAD"
fi
fi
for f in $NVM_DIR/v*; do
if [[ $PATH == *$f/bin* ]]; then
echo "v${f##*v} *"
@ -128,4 +92,4 @@ nvm()
nvm help
;;
esac
}
}