You can download the latest version of Node (4.2.2
) from their website, instead of using the package Debian provides (0.12
). This will also mean you have an updated version of npm. I have not had any problems doing this on Jessie.
Download the .tar.gz
from their website and cd
into that dir (the name of the file is obviously specific to my download):
$ tar -xzvf node-v4.2.2-linux-x64.tar.gz
$ cd node-v4.2.2-linux-x64
If you have a look in the bin folder you will see the binaries you need for node and npm:
$ ls node-v4.2.2-linux-x64/bin
node npm
Now I would rename the folder to something a bit easier to keep track of
$ mv node-v4.2.2-linux-x64 nodejs
If you are not interested in keeping node updated, then simply move this folder into one of your bin locations (I use ~/bin
), and skip the next step.
If you would like to be able to easily update your node version, then move the nodejs
folder somewhere you can keep track of it (~/nodejs
perhaps?). Then you want to create a symlink to one of your bin locations so that the binaries can be used from your shell without writing out the full path.
Assuming you put the nodejs folder in your home directory you can now do:
$ ln -s ~/nodejs ~/bin/nodejs
Obviously, this can go to any bin location you want. I used my home directory so it is only available to me, but you could also easily do:
$ ln -s ~/nodejs /usr/local/bin/nodejs
This will create a symlink from the nodejs folder in your home directory to the bin directory (meaning that any updates to the directory in your home folder are reflected in the folder elsewhere via the symbolic link). Now you want to make sure that the bin folder containing the nodejs directory is in your $PATH
environment variable, so open the ~/.profile
file in your home directory. You want to add this to the bottom of that file (changing the path, if you did not use ~/bin/
):
# Set the node PATH if it exists
if [ -d "$HOME/bin/nodejs/bin" ] ; then
PATH="$HOME/bin/nodejs/bin:$PATH"
fi
This will check if the directory exists, and if it does, add it to your PATH. I use zsh
so I just updated a line in ~/.zshrc
:
export PATH="$HOME/bin/nodejs/bin:$PATH"
Close your terminal and re-open, then type the following to check:
$ node -v
v4.2.2
$ npm -v
2.14.7
By creating the sym link, it now means that in the future, you can download a new .tar.gz
from the Nodejs website, extract it to ~/nodejs
, and the binaries that are available to you in your $PATH
environment variable are automatically updated.