Browse Source

Use version descriptors for 'install' and 'use'

Allows things like "nvm install latest" or "nvm use stable" or "nvm use 0.2"
master
Isaac Wolkerstorfer 14 years ago
parent
commit
0f6680e8b7
  1. 36
      nvm.sh

36
nvm.sh

@ -64,8 +64,10 @@ nvm()
echo " nvm sync Update the local cache of available versions" echo " nvm sync Update the local cache of available versions"
echo echo
echo "Example:" echo "Example:"
echo " nvm install v0.2.5" echo " nvm install v0.2.5 Install a specific version number"
echo " nvm use v0.2.5" echo " nvm use stable Use the stable release"
echo " nvm install latest Install the latest, possibly unstable version"
echo " nvm use 0.3 Use the latest available 0.3.x release"
echo echo
;; ;;
"install" ) "install" )
@ -73,17 +75,18 @@ nvm()
nvm help nvm help
return; return;
fi fi
VERSION=`version $2`
START=`pwd` START=`pwd`
mkdir -p "$NVM_DIR/src" && \ mkdir -p "$NVM_DIR/src" && \
rm -f "$NVM_DIR/$2" && \ rm -f "$NVM_DIR/$2" && \
cd "$NVM_DIR/src" && \ cd "$NVM_DIR/src" && \
wget "http://nodejs.org/dist/node-$2.tar.gz" -N && \ wget "http://nodejs.org/dist/node-$VERSION.tar.gz" -N && \
tar -xzf "node-$2.tar.gz" && \ tar -xzf "node-$VERSION.tar.gz" && \
cd "node-$2" && \ cd "node-$VERSION" && \
./configure --prefix="$NVM_DIR/$2" && \ ./configure --prefix="$NVM_DIR/$VERSION" && \
make && \ make && \
make install && \ make install && \
nvm use $2 nvm use $VERSION
if ! which npm ; then if ! which npm ; then
echo "Installing npm..." echo "Installing npm..."
curl http://npmjs.org/install.sh | sh curl http://npmjs.org/install.sh | sh
@ -109,25 +112,26 @@ nvm()
nvm help nvm help
return return
fi fi
if [ ! -d $NVM_DIR/$2 ]; then VERSION=`version $2`
echo "$2 version is not installed yet" if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed yet"
return; return;
fi fi
if [[ $PATH == *$NVM_DIR/*/bin* ]]; then if [[ $PATH == *$NVM_DIR/*/bin* ]]; then
PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$2/bin${PATH#*$NVM_DIR/*/bin} PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$VERSION/bin${PATH#*$NVM_DIR/*/bin}
else else
PATH="$NVM_DIR/$2/bin:$PATH" PATH="$NVM_DIR/$VERSION/bin:$PATH"
fi fi
if [[ $MANPATH == *$NVM_DIR/*/share/man* ]]; then if [[ $MANPATH == *$NVM_DIR/*/share/man* ]]; then
MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$2/share/man${MANPATH#*$NVM_DIR/*/share/man} MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$VERSION/share/man${MANPATH#*$NVM_DIR/*/share/man}
else else
MANPATH="$NVM_DIR/$2/share/man:$MANPATH" MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH"
fi fi
export PATH export PATH
export MANPATH export MANPATH
export NVM_PATH="$NVM_DIR/$2/lib/node" export NVM_PATH="$NVM_DIR/$VERSION/lib/node"
export NVM_BIN="$NVM_DIR/$2/bin" export NVM_BIN="$NVM_DIR/$VERSION/bin"
echo "Now using node $2" echo "Now using node $VERSION"
;; ;;
"ls" ) "ls" )
if [ $# -ne 1 ]; then if [ $# -ne 1 ]; then

Loading…
Cancel
Save