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.
# 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
# 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.
@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:
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.