Skip to content
Browse files

Adding ability to easily switch between installed node.js versions, a…

…nd a smarter check to see if a new node.js actually needs to be downloaded and installed.
  • Loading branch information...
1 parent c72bf24 commit c89dc97d33c1b1c87f486dc1650e1c5212358fa2 @cowboy committed
Showing with 23 additions and 1 deletion.
  1. +1 −1 init/50_nodejs.sh
  2. +22 −0 source/50_ubuntu.sh
View
2 init/50_nodejs.sh
@@ -9,7 +9,7 @@ if [[ ! "$OSTYPE" =~ ^darwin ]]; then
| tail -n1
)"
- if [[ ! "$(type -P node)" || "$(node --version)" != "v$node_stable" ]]; then
+ if [[ ! "$(type -P node)" || ! -e "/usr/local/src/node-v$node_stable" ]]; then
e_header "Installing Node v$node_stable"
node_url="http://nodejs.org/dist/v$node_stable/node-v$node_stable.tar.gz"
(
View
22 source/50_ubuntu.sh
@@ -9,3 +9,25 @@ alias search="apt-cache search"
# Make 'less' more.
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
+
+# Switch between already-downloaded node versions.
+function node_ver() {
+ (
+ ver="${1#v}"
+ nodes=()
+ if [[ ! -e "/usr/local/src/node-v$ver" ]]; then
+ shopt -s extglob
+ shopt -s nullglob
+ cd "/usr/local/src"
+ eval 'for n in node-v*+([0-9]).+([0-9]).+([0-9]); do nodes=("${nodes[@]}" "${n#node-}"); done'
+ [[ "$1" ]] && echo "Node.js version \"$1\" not found."
+ echo "Valid versions are: ${nodes[*]}"
+ [[ "$(type -P node)" ]] && echo "Current version is: $(node --version)"
+ exit 1
+ fi
+ cd "/usr/local/src/node-v$ver"
+ sudo make install >/dev/null 2>&1 &&
+ echo "Node.js $(node --version) installed." ||
+ echo "Error, $(node --version) installed."
+ )
+}

0 comments on commit c89dc97

Please sign in to comment.
Something went wrong with that request. Please try again.