mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 22:31:51 +00:00
Merge branch 'master' into global_bin
Conflicts: nvm.sh
This commit is contained in:
commit
9029a85133
@ -4,7 +4,22 @@
|
||||
|
||||
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`".
|
||||
### Install script
|
||||
|
||||
To install you could use the [install script](https://github.com/creationix/nvm/blob/master/install.sh) (requires Git) using cURL:
|
||||
|
||||
curl https://raw.github.com/creationix/nvm/master/install.sh | sh
|
||||
|
||||
or Wget:
|
||||
|
||||
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
|
||||
|
||||
<sub>The script clones the Nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile` or `~/.profile`).</sub>
|
||||
|
||||
|
||||
### Manual install
|
||||
|
||||
For manual install create a folder somewhere in your filesystem with the `nvm.sh` file inside it. I put mine in a folder called `nvm`.
|
||||
|
||||
Or if you have `git` installed, then just clone it:
|
||||
|
||||
@ -14,35 +29,38 @@ To activate nvm, you need to source it from your bash shell
|
||||
|
||||
. ~/nvm/nvm.sh
|
||||
|
||||
I always add this line to my ~/.bashrc or ~/.profile file to have it automatically sources upon login.
|
||||
I always add this line to my `~/.bashrc` or `~/.profile` file to have it automatically sourced upon login.
|
||||
Often I also put in a line to use a specific version of node.
|
||||
|
||||
## Usage
|
||||
|
||||
To download, compile, and install the v0.6.14 release of node, do this:
|
||||
|
||||
nvm install 0.6.14
|
||||
To download, compile, and install the latest v0.8.x release of node, do this:
|
||||
|
||||
nvm install 0.8
|
||||
|
||||
And then in any new shell just use the installed version:
|
||||
|
||||
nvm use 0.6.14
|
||||
nvm use 0.8
|
||||
|
||||
Or you can just run it:
|
||||
|
||||
nvm run 0.6.14
|
||||
nvm run 0.8
|
||||
|
||||
If you want to see what versions are available:
|
||||
If you want to see what versions are installed:
|
||||
|
||||
nvm ls
|
||||
|
||||
If you want to see what versions are available to install:
|
||||
|
||||
nvm ls-remote
|
||||
|
||||
To restore your PATH, you can deactivate it.
|
||||
|
||||
nvm deactivate
|
||||
|
||||
To set a default Node version to be used in any new shell, use the alias 'default':
|
||||
|
||||
nvm alias default 0.6
|
||||
nvm alias default 0.8
|
||||
|
||||
## License
|
||||
|
||||
@ -130,3 +148,6 @@ on Arch Linux and other systems using python3 by default, before running *instal
|
||||
|
||||
export PYTHON=python2
|
||||
|
||||
After the v0.8.6 release of node, nvm tries to install from binary packages. But in some systems, the official binary packages don't work due to incompatibility of shared libs. In such cases, use `-s` option to force install from source:
|
||||
|
||||
nvm install -s 0.8.6
|
||||
|
@ -79,4 +79,11 @@ __nvm ()
|
||||
return 0
|
||||
}
|
||||
|
||||
# complete is a bash builtin, but recent versions of ZSH come with a function
|
||||
# called bashcompinit that will create a complete in ZSH. If the user is in
|
||||
# ZSH, load and run bashcompinit before calling the complete function.
|
||||
if [[ -n ${ZSH_VERSION-} ]]; then
|
||||
autoload -U +X bashcompinit && bashcompinit
|
||||
fi
|
||||
|
||||
complete -o default -o nospace -F __nvm nvm
|
||||
|
@ -25,7 +25,7 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
SOURCE_STR='[[ -s "$HOME/.nvm/nvm.sh" ]] && . "$HOME/.nvm/nvm.sh" # This loads NVM'
|
||||
SOURCE_STR="[[ -s "$NVM_TARGET/nvm.sh" ]] && . "$NVM_TARGET/nvm.sh" # This loads NVM"
|
||||
|
||||
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
|
||||
if [ -z $PROFILE ]; then
|
||||
|
110
nvm.sh
110
nvm.sh
@ -16,6 +16,14 @@ if [ ! -z "$(which unsetopt 2>/dev/null)" ]; then
|
||||
unsetopt nomatch 2>/dev/null
|
||||
fi
|
||||
|
||||
# Obtain nvm version from rc file
|
||||
function rc_nvm_version {
|
||||
if [ -e .nvmrc ]; then
|
||||
RC_VERSION=`cat .nvmrc | head -n 1`
|
||||
echo "Found .nvmrc files with version <$RC_VERSION>"
|
||||
fi
|
||||
}
|
||||
|
||||
# Expand a version using the version cache
|
||||
nvm_version()
|
||||
{
|
||||
@ -74,6 +82,7 @@ nvm_ls()
|
||||
nvm_ls_remote()
|
||||
{
|
||||
local PATTERN=$1
|
||||
local VERSIONS
|
||||
if [ "$PATTERN" ]; then
|
||||
if echo "${PATTERN}" | grep -v '^v' ; then
|
||||
PATTERN=v$PATTERN
|
||||
@ -81,7 +90,7 @@ nvm_ls_remote()
|
||||
else
|
||||
PATTERN=".*"
|
||||
fi
|
||||
local VERSIONS=`curl -s http://nodejs.org/dist/ \
|
||||
VERSIONS=`curl -s http://nodejs.org/dist/ \
|
||||
| egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
|
||||
| grep -w "${PATTERN}" \
|
||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
|
||||
@ -150,7 +159,7 @@ nvm()
|
||||
echo
|
||||
echo "Usage:"
|
||||
echo " nvm help Show this message"
|
||||
echo " nvm install <version> Download and install a <version>"
|
||||
echo " nvm install [-s] <version> Download and install a <version>"
|
||||
echo " nvm uninstall <version> Uninstall a version"
|
||||
echo " nvm use <version> Modify PATH to use <version>"
|
||||
echo " nvm run <version> [<args>] Run <version> with <args> as arguments"
|
||||
@ -178,19 +187,35 @@ nvm()
|
||||
local url
|
||||
local sum
|
||||
local tarball
|
||||
local shasum='shasum'
|
||||
local nobinary
|
||||
|
||||
if [ ! `which curl` ]; then
|
||||
echo 'NVM Needs curl to proceed.' >&2;
|
||||
fi
|
||||
|
||||
if [ -z "`which shasum`" ]; then
|
||||
shasum='sha1sum'
|
||||
fi
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
nvm help
|
||||
return
|
||||
fi
|
||||
VERSION=`nvm_remote_version $2`
|
||||
|
||||
shift
|
||||
|
||||
nobinary=0
|
||||
if [ "$1" = "-s" ]; then
|
||||
nobinary=1
|
||||
shift
|
||||
fi
|
||||
|
||||
VERSION=`nvm_remote_version $1`
|
||||
ADDITIONAL_PARAMETERS=''
|
||||
|
||||
shift
|
||||
shift
|
||||
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
|
||||
@ -199,34 +224,37 @@ nvm()
|
||||
|
||||
[ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return
|
||||
|
||||
# shortcut - try the binary if possible.
|
||||
if [ -n "$os" ]; then
|
||||
binavail=
|
||||
# binaries started with node 0.8.6
|
||||
case "$VERSION" in
|
||||
v0.8.[012345]) binavail=0 ;;
|
||||
v0.[1234567]) binavail=0 ;;
|
||||
*) binavail=1 ;;
|
||||
esac
|
||||
if [ $binavail -eq 1 ]; then
|
||||
t="$VERSION-$os-$arch"
|
||||
url="http://nodejs.org/dist/$VERSION/node-${t}.tar.gz"
|
||||
sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt.asc | grep node-${t}.tar.gz | awk '{print $1}'`
|
||||
if (
|
||||
mkdir -p "$NVM_DIR/tmp/node-${t}" && \
|
||||
cd "$NVM_DIR/tmp" && \
|
||||
curl -C - --progress-bar $url -o "node-${t}.tar.gz" && \
|
||||
nvm_checksum `shasum node-${t}.tar.gz | awk '{print $1}'` $sum && \
|
||||
tar -xzf "node-${t}.tar.gz" -C "node-${t}" --strip-components 1 && \
|
||||
mv "node-${t}" "../$VERSION" && \
|
||||
rm -f "node-${t}.tar.gz"
|
||||
)
|
||||
then
|
||||
nvm use $VERSION
|
||||
return;
|
||||
else
|
||||
echo "Binary download failed, trying source." >&2
|
||||
cd "$NVM_DIR/tmp" && rm -rf "node-${t}.tar.gz" "node-${t}"
|
||||
# skip binary install if no binary option specified.
|
||||
if [ $nobinary -ne 1 ]; then
|
||||
# shortcut - try the binary if possible.
|
||||
if [ -n "$os" ]; then
|
||||
binavail=
|
||||
# binaries started with node 0.8.6
|
||||
case "$VERSION" in
|
||||
v0.8.[012345]) binavail=0 ;;
|
||||
v0.[1234567].*) binavail=0 ;;
|
||||
*) binavail=1 ;;
|
||||
esac
|
||||
if [ $binavail -eq 1 ]; then
|
||||
t="$VERSION-$os-$arch"
|
||||
url="http://nodejs.org/dist/$VERSION/node-${t}.tar.gz"
|
||||
sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt | grep node-${t}.tar.gz | awk '{print $1}'`
|
||||
if (
|
||||
mkdir -p "$NVM_DIR/tmp/node-${t}" && \
|
||||
cd "$NVM_DIR/tmp" && \
|
||||
curl -C - --progress-bar $url -o "node-${t}.tar.gz" && \
|
||||
nvm_checksum `${shasum} node-${t}.tar.gz | awk '{print $1}'` $sum && \
|
||||
tar -xzf "node-${t}.tar.gz" -C "node-${t}" --strip-components 1 && \
|
||||
mv "node-${t}" "../$VERSION" && \
|
||||
rm -f "node-${t}.tar.gz"
|
||||
)
|
||||
then
|
||||
nvm use $VERSION
|
||||
return;
|
||||
else
|
||||
echo "Binary download failed, trying source." >&2
|
||||
cd "$NVM_DIR/tmp" && rm -rf "node-${t}.tar.gz" "node-${t}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -246,7 +274,7 @@ nvm()
|
||||
mkdir -p "$NVM_DIR/src" && \
|
||||
cd "$NVM_DIR/src" && \
|
||||
curl --progress-bar $tarball -o "node-$VERSION.tar.gz" && \
|
||||
if [ "$sum" = "" ]; then : ; else nvm_checksum `shasum node-$VERSION.tar.gz | awk '{print $1}'` $sum; fi && \
|
||||
if [ "$sum" = "" ]; then : ; else nvm_checksum `${shasum} node-$VERSION.tar.gz | awk '{print $1}'` $sum; fi && \
|
||||
tar -xzf "node-$VERSION.tar.gz" && \
|
||||
cd "node-$VERSION" && \
|
||||
./configure --prefix="$NVM_DIR/$VERSION" $ADDITIONAL_PARAMETERS && \
|
||||
@ -324,14 +352,26 @@ nvm()
|
||||
fi
|
||||
;;
|
||||
"use" )
|
||||
if [ $# -ne 2 ]; then
|
||||
if [ $# -eq 0 ]; then
|
||||
nvm help
|
||||
return
|
||||
fi
|
||||
if [ $# -eq 1 ]; then
|
||||
rc_nvm_version
|
||||
if [ ! -z $RC_VERSION ]; then
|
||||
VERSION=`nvm_version $RC_VERSION`
|
||||
fi
|
||||
else
|
||||
VERSION=`nvm_version $2`
|
||||
fi
|
||||
if [ -z $VERSION ]; then
|
||||
nvm help
|
||||
return
|
||||
fi
|
||||
VERSION=`nvm_version $2`
|
||||
if [ ! -d $NVM_DIR/$VERSION ]; then
|
||||
echo "$VERSION version is not installed yet"
|
||||
return;
|
||||
return 1
|
||||
fi
|
||||
if [[ $PATH == *$NVM_DIR/*/bin* ]]; then
|
||||
PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$VERSION/bin${PATH#*$NVM_DIR/*/bin}
|
||||
|
14
test/slow/install from binary
Executable file
14
test/slow/install from binary
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
. ../../nvm.sh
|
||||
|
||||
# Remove the stuff we're clobbering.
|
||||
[ -e ../../v0.8.6 ] && rm -R ../../v0.8.6
|
||||
|
||||
# Install from binary
|
||||
nvm install 0.8.6
|
||||
|
||||
# Check
|
||||
[ -d ../../v0.8.6 ]
|
||||
nvm run v0.8.6 --version | grep v0.8.6
|
14
test/slow/install from source
Executable file
14
test/slow/install from source
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
. ../../nvm.sh
|
||||
|
||||
# Remove the stuff we're clobbering.
|
||||
[ -e ../../v0.8.6 ] && rm -R ../../v0.8.6
|
||||
|
||||
# Install from source
|
||||
nvm install -s 0.8.6
|
||||
|
||||
# Check
|
||||
[ -d ../../v0.8.6 ]
|
||||
nvm run v0.8.6 --version | grep v0.8.6
|
Loading…
Reference in New Issue
Block a user