Installing the Latest Version of Node and NPM on CentOS 7
Downloading Node:
- The download uses the Aliyun mirror
mkdir ~/nodejs
cd ~/nodejs
wget https://npm.taobao.org/mirrors/node/latest-v15.x/node-v15.7.0-linux-x64.tar.gz
tar -xvzf node-v15.7.0-linux-x64.tar.gz
Renaming to node
mv node-v15.7.0-linux-x64 node
Configuring Environment Variables
vim /etc/profile
- Add the following at the end of the file
#set for nodejs
export NODE_HOME=/root/nodejs/node
export PATH=$NODE_HOME/bin:$PATH
- After saving and exiting, run the update command
source /etc/profile
If it doesn’t take effect, restart the system.
Verifying Node and NPM Installation
If the version number is displayed, the installation was successful
# node -v
v8.0.0
# npm -v
5.0.0
Note: node and npm are not yet available globally and require linking (use your actual paths)
ln -s /root/nodejs/node/bin/node /usr/local/bin/node
ln -s /root/nodejs/node/bin/npm /usr/local/bin/npm