Skip to content

Instantly share code, notes, and snippets.

@rsp
Last active May 3, 2019 17:26
Show Gist options
  • Save rsp/edf756a05b10f25ee305cc98a161876a to your computer and use it in GitHub Desktop.
Save rsp/edf756a05b10f25ee305cc98a161876a to your computer and use it in GitHub Desktop.
How to get Node 6.7.0 on Linux

How to get Node 6.7.0 on Linux

How to get a specific version of Node on Linux, on the example of Node 6.7.0

Written for this question on Stack Overflow: Nodejs - DeprecationWarning process.EventEmitter is deprecated

If you don't have any Node version installed yet but you want to have it installed globally, it may be easiest to install it in /usr/local as /usr/local/bin is likely already present in your PATH.

If you want to install it in addition to a version of Node that is installed on the system, then maybe /opt/node or /opt/node-6.7.0 would be a better place to install it.

Installing in /usr/local is more risky because you have some other things there. But you don't have to worry about PATH.

Installing in /opt/something is less risky because you can choose a path that didn't exist before. But you have to set your PATH.

You have two options - either install a binary disribution of Node (faster but may not work on your system) or build Node from source (slower but should work on any system with build tools).

The build tools needed to build Node from source are: C/C++ compiler (either gcc and g++ 4.8 or newer, or clang and clang++ 3.4 or newer), Python (version 2.6 or 2.7) and GNU Make (version 3.81 or newer). It's not needed for the binary version of Node.

Installing from binaries

# 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 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

# 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

Installing from source

# Download the source:
wget https://nodejs.org/dist/v6.7.0/node-v6.7.0.tar.gz

# Extract files:
tar xzvf node-v6.7.0.tar.gz

# Go into the extracted directory:
cd node-v6.7.0

# Select where you want to install - run ONE of the below:
./configure --prefix=/usr/local
./configure --prefix=/opt/node
./configure --prefix=/opt/node-6.7.0
# (if the prefix is in your HOME then you will not need sudo in the next commands)

# Build it and test it:
make && make test && echo OK || echo ERROR
# (this can take some time)

# If everything is ok and you see OK and no errors, install it:
sudo make install

You will need to add the correct path to your PATH environment variable if you installed anywhere else than in /usr/local. For example for /opt/node add:

PATH="/opt/node/bin:$PATH"

to your system or user profile (like ~/.profile or ~/.bashrc etc.). Note the "/bin" after the directory that you were installing into - so it's /opt/node/bin and not just /opt/node etc.

If you installed in /opt/node-6.7.0 then you can either add /opt/node-6.7.0/bin to PATH or add /opt/node/bin to PATH and make a symlink /opt/node pointing to /opt/node-6.7.0:

cd /opt
sudo -svf node-6.7.0 node

Instead of adding that drectory to your PATH you can also run your scripts with explicit path, e.g.:

/opt/node-6.7.0/bin/node script.js

Or add the full path to node in the shebang line of your .js programs:

#!/opt/node-6.7.0/bin/node
// your js is here

If you have the shebang line like that and corerct permissions (chmod a+x your-file.js) then you'll be able to run it as:

./your-file.js

If you want to run it as:

node your-file.js

then you will have to have the "bin" directory of the correct version of Node in your PATH.

@pablofernandezorg
Copy link

Getting this error when choosing install location

[pablofernandez@server node-v6.7.0]$ ./configure --prefix=/usr/local
File "./configure", line 486
except OSError, e:
^
SyntaxError: invalid syntax
[pablofernandez@server node-v6.7.0]$

@rsp
Copy link
Author

rsp commented Jul 18, 2017

@pablofernandezcom configure is a Python script and it needs to be run with Python 2.6 or 2.7 specifically (as I wrote in the tutorial above).

From the documentation of both the 6.7.0 version of Node and the current one at the time of this writing:

"Note that the above requires that python resolve to Python 2.6 or 2.7 and not a newer version."

See:

It seems that you may be using some other version of Python that is not supported.

Make sure that running python -V in the command line prints either Python 2.6.x or 2.7.x.

@jim-at-miramontes
Copy link

I'm trying to install node 12.1.0 from source with CentOS 6.10, gcc 6.5.0, and CERN devtools-7. "configure" runs fine, but "make" throws an error:

# make
make -C out BUILDTYPE=Release V=0
make[1]: Entering directory `/opt/node-source/node-v12.1.0/out'
  g++ -o /opt/node-source/node-v12.1.0/out/Release/obj.host/torque_base/deps/v8/src/torque/cfg.o ../deps/v8/src/torque/cfg.cc '-DV8_GYP_BUILD' '-DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64' '-DOPENSSL_THREADS' '-DOPENSSL_NO_ASM' '-DV8_TARGET_ARCH_X64' '-DV8_EMBEDDER_STRING="-node.16"' '-DENABLE_DISASSEMBLER' '-DV8_PROMISE_INTERNAL_FIELD_COUNT=1' '-DENABLE_MINOR_MC' '-DV8_INTL_SUPPORT' '-DV8_USE_SNAPSHOT' '-DV8_CONCURRENT_MARKING' '-DV8_EMBEDDED_BUILTINS' '-DV8_USE_SIPHASH' '-DDISABLE_UNTRUSTED_CODE_MITIGATIONS' -I../deps/v8 -I../deps/v8/include  -pthread -Wno-unused-parameter -m64 -fno-strict-aliasing -m64 -O3 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -O3 -fno-rtti -fno-exceptions -std=gnu++1y -MMD -MF /opt/node-source/node-v12.1.0/out/Release/.deps//opt/node-source/node-v12.1.0/out/Release/obj.host/torque_base/deps/v8/src/torque/cfg.o.d.raw   -c
/tmp/ccRFCkxT.s: Assembler messages:
/tmp/ccRFCkxT.s:4076: Error: expecting string instruction after `rep'
make[1]: *** [/opt/node-source/node-v12.1.0/out/Release/obj.host/torque_base/deps/v8/src/torque/cfg.o] Error 1
make[1]: Leaving directory `/opt/node-source/node-v12.1.0/out'
make: *** [node] Error 2

I've found a reference to this in nodejs/node#26933 (regarding devtoolset-2, anyway), but it's not clear what to do about it (they claim there was a config error in the devtoolset-2 utils that should be fixed, but not what the problem was). Anyway, does anyone have any advice here? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment