mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-12-11 15:44:19 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e0406e95b | ||
|
|
d3b5853454 | ||
|
|
077a661696 | ||
|
|
b69a2b7fc3 | ||
|
|
924d965964 | ||
|
|
926ea1d8e9 | ||
|
|
4fb13d113e | ||
|
|
dd32e5880d | ||
|
|
9ef89f51c9 | ||
|
|
b82bcfbd47 | ||
|
|
a078d6427b | ||
|
|
91d2be5179 | ||
|
|
c657328c8d | ||
|
|
641cbb634d | ||
|
|
d143b5f491 | ||
|
|
e0bbea635f | ||
|
|
fefa00fac8 | ||
|
|
359a83e6c5 | ||
|
|
06e882b332 | ||
|
|
b542e3e205 | ||
|
|
1938f6931c | ||
|
|
7df245c569 | ||
|
|
2527ff6b1f | ||
|
|
d67c7011f4 | ||
|
|
09e7c3227b | ||
|
|
93e28c3b2f |
2
.npmignore
Normal file
2
.npmignore
Normal file
@@ -0,0 +1,2 @@
|
||||
src
|
||||
v*
|
||||
@@ -2,44 +2,36 @@
|
||||
|
||||
## 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`".
|
||||
|
||||
Or if you have `git` installed, then just clone it:
|
||||
|
||||
git clone git://gist.github.com/367305.git ~/.nvm
|
||||
git clone git://github.com/creationix/nvm.git ~/.nvm
|
||||
|
||||
Then add three lines to your bash profile:
|
||||
To activate nvm, you need to source it from your bash shell
|
||||
|
||||
NVM_DIR=$HOME/.nvm
|
||||
. $NVM_DIR/nvm.sh
|
||||
nvm use v0.1.91
|
||||
. ~/.nvm/nvm.sh
|
||||
|
||||
The first line tells your system where NVM is installed, you should already have nvm.sh there. The second line loads the nvm function into your bash shell so that it's available as a command. The third line sets your default node version.
|
||||
I always add this line to my ~/.bashrc or ~/.profile file to have it automatically sources upon login.
|
||||
Often I also put in a line to use a specific version of node.
|
||||
|
||||
## Usage
|
||||
|
||||
To download, install, and use the v0.1.91 release of node do this:
|
||||
To download, compile, and install the v0.2.5 release of node, do this:
|
||||
|
||||
nvm install v0.1.91
|
||||
nvm install v0.2.5
|
||||
|
||||
And then in any new shell just use the installed version:
|
||||
|
||||
nvm use v0.1.91
|
||||
|
||||
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
|
||||
|
||||
|
||||
22
install.sh
Executable file
22
install.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
dir=$npm_config_root/.npm/$npm_package_name/$npm_package_version/package
|
||||
|
||||
# add lines to the bashrc.
|
||||
has=$(cat ~/.bashrc | egrep "^# ADDED BY npm FOR NVM$" || true)
|
||||
if [ "x$has" != "x" ]; then
|
||||
exit 0
|
||||
fi
|
||||
cat <<NVM_CODE >>~/.bashrc
|
||||
# ADDED BY npm FOR NVM
|
||||
. $dir/nvm.sh
|
||||
# END ADDED BY npm FOR NVM
|
||||
NVM_CODE
|
||||
|
||||
cat <<NVM_HOWTO
|
||||
|
||||
To use nvm, source your .bashrc file like this:
|
||||
. ~/.bashrc
|
||||
or log out and back into your terminal.
|
||||
|
||||
NVM_HOWTO
|
||||
84
nvm.sh
84
nvm.sh
@@ -5,9 +5,11 @@
|
||||
# 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`
|
||||
if [ $# -lt 1 ]; then
|
||||
nvm help
|
||||
return
|
||||
@@ -18,50 +20,23 @@ 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 clone (Clone and install HEAD version)"
|
||||
echo " nvm update (Pull and rebuild HEAD version)"
|
||||
echo " nvm list (Show all installed versions)"
|
||||
echo " nvm use version (Set this version in the PATH)"
|
||||
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.91"
|
||||
echo " nvm install v0.2.5"
|
||||
echo " nvm use v0.2.5"
|
||||
echo
|
||||
;;
|
||||
"clone" )
|
||||
if [ $# -ne 1 ]; then
|
||||
nvm help
|
||||
return;
|
||||
fi
|
||||
mkdir -p "$NVM_DIR/src" && \
|
||||
cd "$NVM_DIR/src" && \
|
||||
git clone git://github.com/ry/node.git && \
|
||||
cd node && \
|
||||
./configure --debug --prefix="$NVM_DIR/HEAD" && \
|
||||
make && \
|
||||
make install && \
|
||||
nvm use HEAD
|
||||
cd $START
|
||||
;;
|
||||
"update" )
|
||||
if [ $# -ne 1 ]; then
|
||||
nvm help
|
||||
return;
|
||||
fi
|
||||
cd "$NVM_DIR/src/node" && \
|
||||
git pull origin master && \
|
||||
./configure --debug --prefix="$NVM_DIR/HEAD" && \
|
||||
make clean all && \
|
||||
make install && \
|
||||
nvm use HEAD
|
||||
cd $START
|
||||
;;
|
||||
"install" )
|
||||
if [ $# -ne 2 ]; then
|
||||
nvm help
|
||||
return;
|
||||
fi
|
||||
START=`pwd`
|
||||
mkdir -p "$NVM_DIR/src" && \
|
||||
cd "$NVM_DIR/src" && \
|
||||
wget "http://nodejs.org/dist/node-$2.tar.gz" -N && \
|
||||
@@ -71,12 +46,30 @@ nvm()
|
||||
make && \
|
||||
make install && \
|
||||
nvm use $2
|
||||
if ! which npm ; then
|
||||
echo "Installing npm..."
|
||||
curl http://npmjs.org/install.sh | sh
|
||||
fi
|
||||
cd $START
|
||||
;;
|
||||
"deactivate" )
|
||||
if [[ $PATH == *$NVM_DIR/*/bin* ]]; then
|
||||
export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:}
|
||||
echo "$NVM_DIR/*/bin removed from \$PATH"
|
||||
else
|
||||
echo "Could not find $NVM_DIR/*/bin in \$PATH"
|
||||
fi
|
||||
if [[ $MANPATH == *$NVM_DIR/*/share/man* ]]; then
|
||||
export MANPATH=${MANPATH%$NVM_DIR/*/share/man*}${MANPATH#*$NVM_DIR/*/share/man:}
|
||||
echo "$NVM_DIR/*/share/man removed from \$MANPATH"
|
||||
else
|
||||
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH"
|
||||
fi
|
||||
;;
|
||||
"use" )
|
||||
if [ $# -ne 2 ]; then
|
||||
nvm help
|
||||
return;
|
||||
return
|
||||
fi
|
||||
if [ ! -d $NVM_DIR/$2 ]; then
|
||||
echo "$2 version is not installed yet"
|
||||
@@ -87,21 +80,22 @@ nvm()
|
||||
else
|
||||
PATH="$NVM_DIR/$2/bin:$PATH"
|
||||
fi
|
||||
if [[ $MANPATH == *$NVM_DIR/*/share/man* ]]; then
|
||||
MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$2/share/man${MANPATH#*$NVM_DIR/*/share/man}
|
||||
else
|
||||
MANPATH="$NVM_DIR/$2/share/man:$MANPATH"
|
||||
fi
|
||||
export PATH
|
||||
export MANPATH
|
||||
export NVM_PATH="$NVM_DIR/$2/lib/node"
|
||||
export NVM_BIN="$NVM_DIR/$2/bin"
|
||||
echo "Now using node $2"
|
||||
;;
|
||||
"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} *"
|
||||
|
||||
6
package.json
Normal file
6
package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{ "name" : "nvm"
|
||||
, "version" : "0.0.6"
|
||||
, "author" : "Tim Caswell <tim@creationix.org>"
|
||||
, "scripts" :
|
||||
{ "install" : "./install.sh" , "uninstall" : "./uninstall.sh" }
|
||||
}
|
||||
23
uninstall.sh
Executable file
23
uninstall.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
has=$(cat ~/.bashrc | egrep "^# ADDED BY npm FOR NVM$" || true)
|
||||
if [ "x$has" == "x" ]; then
|
||||
echo "doesn't have it, exiting"
|
||||
exit 0
|
||||
fi
|
||||
tmp=~/.bashrc.tmp
|
||||
cat ~/.bashrc | {
|
||||
incode=0
|
||||
while read line; do
|
||||
if [ "$line" == "# ADDED BY npm FOR NVM" ]; then
|
||||
incode=1
|
||||
elif [ "$line" == "# END ADDED BY npm FOR NVM" ] \
|
||||
&& [ $incode -eq 1 ]; then
|
||||
incode=0
|
||||
elif [ $incode -eq 0 ]; then
|
||||
echo "$line" >> $tmp
|
||||
fi
|
||||
done
|
||||
}
|
||||
mv $tmp ~/.bashrc
|
||||
Reference in New Issue
Block a user