How to install Node v4.2.2 gracefully in CentOS inside?

  node.js, question

Recently, some projects began to use ES6 to write Node.

Just like other projects, in order to keep the development environment and production environment as consistent as possible, we use Vagrant as the development environment, but when writing the node installation script, we encounter a headache problem.

In the past, Node 0.x only needed to passyum install -y nodejsNode can be installed. However, Node installed by yum can only be installed to version 0.10.40, not version 4.2.2, which makes it impossible to write ES6 happily.

I tried to compile the source code, but it took too long.

I tried to install it through binary files, but encountered some problems in configuring environment variables.

I don’t know how you gracefully installed Node 4.2.2 in CentOS inside.

# curl -o  node-4.2.2.tar.gz
 # tar -zxvf  node-4.2.2.tar.gz -C /opt
 # mkdir /opt/npm-path
 # mkdir /opt/npm-path/npm-global
 # mkdir /opt/npm-path/npm-cache
 # echo 'export NODE_HOME=/opt/node-v4.2.2-linux-x64
 export PATH=${NODE_HOME}/bin:${PATH}'>/etc/profile.d/
 # echo 'export NPM_PATH_GLOBAL=/opt/npm-path/npm-global
 export NPM_PATH_CACHE=/opt/npm-path/npm-cache
 export PATH=${PATH}:${NPM_PATH_GLOBAL}/bin:${NPM_PATH_CACHE}'>/etc/profile.d/
 # chmod plus x /etc/profile.d/
 # chmod plus x /etc/profile.d/
 # source /etc/profile.d/
 # source /etc/profile.d/
 # exit
 # npm config set prefix /opt/npm-path/npm-global
 # npm config set cache /opt/npm-path/npm-cache
 # node -v
 # npm -v