install any node.js version on debian
any version of node.js on any debian systems from source, the debian way.
People have asked me for a script to install newer versions of node.js, so I felt that it made sense to spend some time rewriting it to post it. This has been tested on Debian Wheezy and Linux Mint Debian Edition, and should work on any debian-based OS.
If you run the script with a commandline argument, like ./install_nodejs 0.10.25 then it will install the 'v0.10.25-release branch of node.js'.
If you run it without an argument, it will default to the latest release version according to http://nodejs.org.
There should be plenty of comments and echo statements to explain every part of the script, but feel free to comment at the bottom of the page if you see any room for improvement.
install_nodejs
#!/bin/bash
#
# Install any release version of node.js.
# Benjamin H. Graham <bman_at_bman.io>
# Download: http://bman.io/i/install_nodejs
# Usage: ./install_nodejs <release version>
# These 2 lines keep apt quiet. Very useful for automated installs.
export DEBIAN_FRONTEND=noninteractive;
export APTOPT='-y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold --yes --fix-missing -qq';
# Function to differentiate the script output.
a8echo () { echo -e "-*- $@" >&2; }
a8echo "This program will build and install node.js for Debian based systems. sudo password required to install deb packages.";
# Set the version to what is supplied or the latest if no version given.
if [ ${1} ]; then
version=${1};
else
version=$(curl -s nodejs.org|grep 'class="version"'|sed -e 's/.*Version: v\(.*\)<\/p\>.*/\1/');
fi;
# Set variable for architecture to build for.
arch=$(dpkg --print-architecture);
# Main install routine
a8echo "Updating apt repos and installing dependencies.";
sudo apt-get update -qq && sudo apt-get $APTOPT install git-core curl build-essential openssl libssl-dev python g++ make checkinstall libc-ares2 libc6 libgcc1 libssl1.0.0 libstdc++6 libv8-3.14.5 zlib1g;
a8echo "Downloading node.js GIT repository.";
git clone --depth 1 -b v${version}-release --single-branch https://github.com/joyent/node.git nodejs-${version} && cd nodejs-${version};
a8echo "Configuring node.js package.";
# Configure seems not to find libssl by default so we give it an explicit pointer.
./configure --openssl-libpath=/usr/lib/ssl
a8echo "Debian package for node.js v${version}-release" > description-pak;
a8echo "Building and installing nodejs package for release version, ${version}.";
sudo checkinstall -D -y --install=yes --pkgname=nodejs --pkgversion=${version} --pkgarch=${arch} --pkgrelease='bman-1' \
--maintainer='Benjamin H Graham \<bman@bman.io\>' --default --pkglicense='Node License' \
--requires=libc-ares2,libc6,libgcc1,libssl1.0.0,libstdc++6,libv8-3.14.5,zlib1g;
a8echo "Testing that nodejs package installed and node and npm binaries are working.";
node -v; # it's alive!
npm -v; # it's alive!
a8echo "Installation complete. As long as you see the version information above, you are good to go.";
Save the contents as install_nodejs and then run it with:
./install_nodejs <release version number (optional)>