Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9cd2dd0
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Node Version Manager | ||
# Implemented as a bash function | ||
# To use source this file from your bash profile | ||
# | ||
# Implemented by Tim Caswell <tim@creationix.com> | ||
# with much bash help from Matthew Ranney | ||
|
||
NVM_DIR=$HOME/.nvm | ||
|
||
nvm() | ||
{ | ||
START=`pwd` | ||
if [ $# -lt 1 ]; then | ||
nvm help | ||
return | ||
fi | ||
case $1 in | ||
"help" ) | ||
echo | ||
echo "Node Version Manager" | ||
echo "Usage:" | ||
echo " nvm install version" | ||
echo " nvm use version" | ||
echo | ||
;; | ||
"install" ) | ||
if [ $# -lt 2 ]; then | ||
nvm help | ||
return; | ||
fi | ||
echo $START | ||
mkdir -p "$NVM_DIR/src" && \ | ||
cd "$NVM_DIR/src" && \ | ||
wget "http://nodejs.org/dist/node-$2.tar.gz" -N && \ | ||
tar -xzf "node-$2.tar.gz" && \ | ||
cd "node-$2" && \ | ||
./configure --prefix="$NVM_DIR/$2" && \ | ||
make && \ | ||
make install && \ | ||
nvm use $2 | ||
cd $START | ||
;; | ||
"use" ) | ||
if [ $# -lt 2 ]; then | ||
nvm help | ||
return; | ||
fi | ||
# TODO: Remove old nvm paths before adding this one | ||
PATH="$NVM_DIR/$2/bin:$PATH" | ||
echo "Now using node $2" | ||
;; | ||
* ) | ||
nvm help | ||
;; | ||
esac | ||
} |