Prerequisites
I assume you are on a Unix-like host, with a bash shell, wget, tar, an Internet connection and that your $HOME environment variable is defined properly. You will need Python >= 2.6 and all the prerequisites necessary to build Node.js from sources: check out the Installation page on Node.js wiki.
Wanna Node NOW!
For the impatient, just copy the following commands and paste it in your shell prompt
NODEJS_ROOT=${NODEJS_ROOT:-~/nodejs}
cd /tmp
wget -N http://nodejs.org/dist/node-latest.tar.gz && tar xzf node-latest.tar.gz
NODEJS_CURRENT=$(tar tf node-latest.tar.gz|head -1)
mkdir -p $NODEJS_ROOT/$NODEJS_CURRENT
cd $NODEJS_CURRENT
./configure --prefix=$NODEJS_ROOT/$NODEJS_CURRENT && make install
cd $NODEJS_ROOT
rm current 2> /dev/null # Removes current symbolic link, if any
ln -s $NODEJS_CURRENT current
echo Do not forget to edit your environment http://blog.g14n.info/2013/01/install-nodejs-without-sudo.html#edit-your-environment
echo Happy coding!
If it is the first time you install Node.js for that user in that host, go to Edit your environment section, otherwise you will miss node binary in your PATH.
Note that, before launching commands, you can set NODEJS_ROOT environment variable to point to your target location otherwise it will default to ~/nodejs.
Installation steps
Situate it
Only once
Choose your local folder, wherever you have enough space and read/write rights. Set a NODEJS_ROOT environment variabile, so you can use it during installation process.
$ NODEJS_ROOT=~/nodejs # or whatever
Get it
Go to a temporary folder, /tmp for instance and get latest Node.js source.
You will see a node-vX.Y.Z folder, that is node-v0.8.17 right now, containing the latest Node.js sources. The -N
flag, will overwrite file and download it only if it is newer.
$ cd /tmp
$ wget -N http://nodejs.org/dist/node-latest.tar.gz && tar xzf node-latest.tar.gz
Build it
Now, figure out what is current version so you can point to the target directory (a.k.a. prefix) and compile Node.js sources.
$ NODEJS_CURRENT=$(tar tf node-latest.tar.gz|head -1)
$ mkdir -p $NODEJS_ROOT/$NODEJS_CURRENT
$ cd $NODEJS_CURRENT
$ ./configure --prefix=$NODEJS_ROOT/$NODEJS_CURRENT && make install
Update it
When compilation ends successful, update or create a simbolic link to your current installation. This will make it easier to upgrade to next version.
$ cd $NODEJS_ROOT
$ rm current 2> /dev/null # Removes current symbolic link, if any
$ ln -s $NODEJS_CURRENT current
Edit your environment
Only once
Add permanently NODEJS_ROOT variable to your environment, and add node and npm binaries to your PATH. This is one way to do it:
$ echo "export NODEJS_ROOT=$NODEJS_ROOT" >> $HOME/.bash_profile
$ echo 'export PATH=$NODEJS_ROOT/current/bin:$PATH' >> $HOME/.bash_profile
$ source $HOME/.bash_profile # reload your env, so you can use node right now
No comments:
Post a Comment