2

I've downloaded Node.js directly from https://nodejs.org/en/ onto my Ubuntu Desktop operating system. I can easily unpackage the node-vX.X.0-linux-x64.tar.xz file, and I can see node directories: bin, include, lib, share. I'm guessing my download folder, ~/Downloads/node-vX.X.0-linux-x64, is not going to be the final installation location.

My guess would be to copy all of the directory over to /usr/bin/node/node-vX.X.-linux-x64 but I'm not really sure.

Where do these files go? (I've tried the readme.md file in the download and the docs on that site. I would have thought something, somewhere on nodejs.org would have offered a bit of help...)

Is there a special installation step required here?

zipzit
  • 3,778
  • 4
  • 35
  • 63
  • Why don't you just use a package manager to install nodejs on Ubuntu ? – codtex Feb 17 '17 at 08:58
  • I would suggest you use nvm because it allows you to install multiple Node.js versions in parallel and switch easily between them: https://github.com/creationix/nvm – Alexander Zeitler Feb 17 '17 at 08:59
  • @sand and Alexander.. those are great recommendations, but that just raises the question "Why does the site http://nodejs.org/en provide binaries for linux instead of simple instructions for a package install?" I'm not saying no to a package install technique, I'm trying to understand why did they do it that way? – zipzit Feb 17 '17 at 09:09
  • According to this link http://www.hostingadvice.com/how-to/install-nodejs-ubuntu-14-04/#standard-binary-packages you should unpack the archive in /usr/local folder – codtex Feb 17 '17 at 09:20
  • @sand, thx for the link. I figured I can't be the first person to have this problem and I was checking the nodejs github issues list... Found [this issue](https://github.com/nodejs/help/issues/418) and one of the recommended fixes is nearly the same code as you offered up. – zipzit Feb 17 '17 at 10:03

1 Answers1

6

I wrote a tutorial to do exactly what you're asking: How to get Node 6.7.0 on Linux - it's about Node 6.7.0 but you can just change the version number.

In short:

First get the files:

# If you have a 64-bit system then download binary package:
wget https://nodejs.org/dist/v6.7.0/node-v6.7.0-linux-x64.tar.gz

# If you have a 32-bit system then download a different version:
wget https://nodejs.org/dist/v6.7.0/node-v6.7.0-linux-x86.tar.gz

Extract:

# Extract what you downloaded:
tar xzvf node-v6.7.0-linux-x64.tar.gz

# Change the file ownership:
sudo chown -Rv root.root node-v6.7.0-linux-x64

Then install in ONE of the locations:

# Install files in /usr/local
sudo cp -Rvi node-v6.7.0-linux-x64/{bin,include,lib,share} /usr/local
# (change -Rvi to -Rvf if you want to overwrite existing files)

# Install files in /opt/node
sudo cp -Rvi node-v6.7.0-linux-x64 /opt/node

# Install files in /opt/node-6.7.0
sudo cp -Rvi node-v6.7.0-linux-x64 /opt/node-6.7.0

The difference between those 3 locations in the example is explained better in the article. The consequences are mostly related to PATH and installing multiple versions.

Finish the setup:

You need to make sure that directory where you have the node and npm binaries is in your PATH. See my tutorial for details on how to do that.

Beware of shebang lines:

The shebang line of npm in Node installed from binaries is different than when installed from sources. This is one of the reasons I recommand building from sources if you have time for that. The other reason is that installing from sources you can do make test to test the version of Node on your specific system, which you cannot do when installing from binaries or with nvm.

rsp
  • 107,747
  • 29
  • 201
  • 177