How to install latest NodeJS on Debian Jessie?

109

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

You can follow the official node.js documentation to install the latest version with package manager.

Node.js v6:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Node.js v7:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

Running the latter, node v7.5.0 and npm v4.1.2 was installed on my system. Both node and nodejs aliases were enabled for Node automatically.

Solution 5

You can download latest Linux Binaries (.tar.gz) from official site and use it https://stackoverflow.com/a/23084499/1197421

Share:
109

Related videos on Youtube

Chris Jones
Author by

Chris Jones

Updated on September 18, 2022

Comments

  • Chris Jones
    Chris Jones over 1 year

    I have a situation where I need to output some code that simultaneously zooms a div from 0 to it's "final" size whilst moving it down from the top of the screen.

    The x and y final sizes could be different every time but my code WILL know them (the div will contain a user-supplied image so I can just read the image size).

    Now, I can do the code to "zoom" the div and also move it down the screen. I know how to find the y-center of the browser window etc...

    I am moving it down the screen by adding "yvalue" to the topMargin.

    Here is where I am stuck and I guess it is more of a math question rather than code??

    Q: How do I calculate what "yvalue" (the y position increment) should be so that the div arrives in the center of the screen at the same time (roughly) that the div zooms to maximum size. Also I need to find out what the corresponding div_xvalue and div_yvalue should be to make the "zoom" happen at the same time (if that makes sense)

    Please assume the following variables :

    yvalue = increment to add to div topMargin each iteration
    zoom_x_final =  final width of div
    zoom_y_final =  final height of div
    browser_center_y = center position of browser window (y direction)
    x = current x size of div
    y = current y size of div
    div_xvalue = value to add to x for increasing div size per iteration
    div_yvalue = value to add to y for increasing div size per iteration
    stop_y = center screen position stop for slide down calc'd from    browser_center_y-(zoom_y_final/2)
    
  • Peter Krauss
    Peter Krauss over 8 years
    ops, use it, but now there are setup_4.x... redo curl and apt-get ok?
  • seniorpreacher
    seniorpreacher over 8 years
    As you might need the newest, actual version, I recommend to visit their site: github.com/nodesource/distributions.
  • artfulrobot
    artfulrobot over 7 years
    This one worked for me since it also gave a working npm.
  • Admin
    Admin about 7 years
    Why wouldn't you trust it if it comes through a secure connection from the same source you're running binaries from
  • user394
    user394 almost 7 years
    apt-get cache update returned E: Invalid operation cache so I ran sudo aptitude update.
  • Jérôme
    Jérôme almost 7 years
    @acidzombie24 right, but even if you trust the code for not being evil, there is always the chance of a mistake in the script, or an outdated script, or your config being a bit exotic. Or maybe you like to order your sources.list some way and the scripts does otherwise. Anyway, I also think it is bad practice and beginners (I'm not aiming at the OP but in general) should not be encouraged to do that. Especially when performing the action manually is much more straightforward than examining the script.