Merge branch 'master' of github.com:creationix/nvm

This commit is contained in:
Daniel Bretoi 2014-07-05 16:08:34 -07:00
commit cbfddf432e
5 changed files with 44 additions and 34 deletions

View File

@ -8,17 +8,17 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w
To install you could use the [install script][2] using cURL: To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash
or Wget: or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub> <sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install. You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install.
<sub>*NB. The installer can use Git, cURL or Wget to download NVM, whatever is available.*</sub> <sub>*NB. The installer can use Git, curl, or wget to download NVM, whatever is available.*</sub>
### Manual install ### Manual install
@ -163,7 +163,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
nvm install -s 0.8.6 nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git [1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.8.0/install.sh [2]: https://github.com/creationix/nvm/blob/v0.10.0/install.sh
[3]: https://travis-ci.org/creationix/nvm [3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin [Urchin]: https://github.com/scraperwiki/urchin

View File

@ -2,7 +2,7 @@
set -e set -e
has() { nvm_has() {
type "$1" > /dev/null 2>&1 type "$1" > /dev/null 2>&1
return $? return $?
} }
@ -11,39 +11,39 @@ if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm" NVM_DIR="$HOME/.nvm"
fi fi
if ! has "curl"; then if ! nvm_has "curl"; then
if has "wget"; then if nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
curl() { curl() {
ARGS="$* " ARGS="$* "
ARGS=${ARGS/-s /-q } ARGS=${ARGS/-s /-q }
ARGS=${ARGS/-o /-O } ARGS=${ARGS/-o /-O }
wget $ARGS wget "$ARGS"
} }
fi fi
fi fi
install_from_git() { install_nvm_from_git() {
if [ -z "$NVM_SOURCE" ]; then if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://github.com/creationix/nvm.git" NVM_SOURCE="https://github.com/creationix/nvm.git"
fi fi
if [ -d "$NVM_DIR/.git" ]; then if [ -d "$NVM_DIR/.git" ]; then
echo "=> nvm is already installed in $NVM_DIR, trying to update" echo "=> nvm is already installed in $NVM_DIR, trying to update"
echo -e "\r=> \c" printf "\r=> "
cd "$NVM_DIR" && git pull 2> /dev/null || { cd "$NVM_DIR" && (git pull 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.."
} })
else else
# Cloning to $NVM_DIR # Cloning to $NVM_DIR
echo "=> Downloading nvm from git to '$NVM_DIR'" echo "=> Downloading nvm from git to '$NVM_DIR'"
echo -e "\r=> \c" printf "\r=> "
mkdir -p "$NVM_DIR" mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR" git clone "$NVM_SOURCE" "$NVM_DIR"
fi fi
} }
install_as_script() { install_nvm_as_script() {
if [ -z "$NVM_SOURCE" ]; then if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/master/nvm.sh" NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/master/nvm.sh"
fi fi
@ -63,28 +63,28 @@ install_as_script() {
if [ -z "$METHOD" ]; then if [ -z "$METHOD" ]; then
# Autodetect install method # Autodetect install method
if has "git"; then if nvm_has "git"; then
install_from_git install_nvm_from_git
elif has "curl"; then elif nvm_has "curl"; then
install_as_script install_nvm_as_script
else else
echo >&2 "You need git, curl or wget to install nvm" echo >&2 "You need git, curl, or wget to install nvm"
exit 1 exit 1
fi fi
else else
if [ "$METHOD" = "git" ]; then if [ "$METHOD" = "git" ]; then
if ! has "git"; then if ! nvm_has "git"; then
echo >&2 "You need git to install nvm" echo >&2 "You need git to install nvm"
exit 1 exit 1
fi fi
install_from_git install_nvm_from_git
fi fi
if [ "$METHOD" = "script" ]; then if [ "$METHOD" = "script" ]; then
if ! has "curl"; then if ! nvm_has "curl"; then
echo >&2 "You need curl or wget to install nvm" echo >&2 "You need curl or wget to install nvm"
exit 1 exit 1
fi fi
install_as_script install_nvm_as_script
fi fi
fi fi
@ -104,8 +104,8 @@ fi
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm" SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
if [ -z $PROFILE ]; then if [ -z "$PROFILE" ]; then
echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile." echo "=> Profile not found. Tried ~/.bash_profile, ~/.zshrc, and ~/.profile."
echo "=> Create one of them and run this script again" echo "=> Create one of them and run this script again"
else else
echo "=> Profile $PROFILE not found" echo "=> Profile $PROFILE not found"
@ -113,16 +113,15 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
fi fi
echo " OR" echo " OR"
echo "=> Append the following lines to the correct file yourself:" echo "=> Append the following lines to the correct file yourself:"
echo -e "$SOURCE_STR" printf "%s" "$SOURCE_STR"
echo echo
else else
if ! grep -qc 'nvm.sh' $PROFILE; then if ! grep -qc 'nvm.sh' "$PROFILE"; then
echo "=> Appending source string to $PROFILE" echo "=> Appending source string to $PROFILE"
echo -e "$SOURCE_STR" >> "$PROFILE" printf "%s" "$SOURCE_STR" >> "$PROFILE"
else else
echo "=> Source string already in $PROFILE" echo "=> Source string already in $PROFILE"
fi fi
fi fi
echo "=> Close and reopen your terminal to start using nvm" echo "=> Close and reopen your terminal to start using nvm"

12
nvm.sh
View File

@ -274,7 +274,7 @@ nvm() {
echo " nvm alias default 0.10.24 Set default node version on a shell" echo " nvm alias default 0.10.24 Set default node version on a shell"
echo echo
echo "Note:" echo "Note:"
echo " to remove, delete or uninstall nvm - just remove ~/.nvm, ~/.npm and ~/.bower folders" echo " to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders"
echo echo
;; ;;
@ -572,11 +572,15 @@ nvm() {
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;; ;;
"ls" | "list" ) "ls" | "list" )
nvm_print_versions "`nvm_ls $2`" local NVM_LS_OUTPUT
local NVM_LS_EXIT_CODE
NVM_LS_OUTPUT=$(nvm_ls "$2")
NVM_LS_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_OUTPUT"
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
nvm alias nvm alias
fi fi
return return $NVM_LS_EXIT_CODE
;; ;;
"ls-remote" | "list-remote" ) "ls-remote" | "list-remote" )
nvm_print_versions "`nvm_ls_remote $2`" nvm_print_versions "`nvm_ls_remote $2`"
@ -651,7 +655,7 @@ nvm() {
nvm_version $2 nvm_version $2
;; ;;
"--version" ) "--version" )
echo "0.8.0" echo "0.10.0"
;; ;;
"unload" ) "unload" )
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1 unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1

View File

@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.8.0", "version": "0.10.0",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": { "directories": {
"test": "test" "test": "test"

View File

@ -0,0 +1,7 @@
#!/bin/sh
. ../../nvm.sh
nvm ls nonexistent_version
[ "$?" = "3" ]