How to install latest NodeJS on Debian Jessie?
There is a setup script available for Node.js (see installation insctructions):
# Adapt version number to the version you want
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs
A little comment: In my humble opinion, it's a very bad idea to curl | sudo bash
. You are running a script you did not check with root privileges. It's always better to download the script, read through it, check for malicious commands, and after that, run it. But that's just my two cents.
The installation can be achieved manually in a few steps following the manual installation procedure:
- Remove old PPA (if applicable)
- Add node repo ssh key
- Add node repo to
sources.list
- update package list and install using favorite apt tool
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.
in my case, I executed the recommended shell commands:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
the problem was that bash script didn't update my APT pinning so apt-get installed the default, old Debian package from the debian.org source and not from nodesource.com
verify this is the problem with apt-cache policy nodejs
. you should see something like Candidate: 6.10.2-1nodesource1~jessie1
and not Candidate: 0.10.29~dfsg-2
to set pin priority to nodesource, add a file in /etc/apt/preferences.d/
called node
or whatever with this content:
Package: nodejs
Pin: release o=Node Source
Pin-Priority: 1200
save and run apt-get cache update
. then try apt-cache policy nodejs
again. if candidate looks right, install as normal apt-get install nodejs