How to install nodejs in CentOS7
This article will explain in detail how to install nodejs in CentOS7, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
1. Confirm dependence on the environment
Make sure that the server has nodejs compilation and dependent software, if not, you can install it by running the following command.
Yum-y install gcc gcc-c++ openssl-devel
2. Download the NodeJS source package and decompress it
Go to the directory where you want to store the download resources, and this article is stored in the / usr/local/src/ directory. Then execute the command to download the source package:
Wget https://npm.taobao.org/mirrors/node/v10.16.1/node-v10.16.1-linux-x64.tar.gz
Decompression
Tar-zxvf node-v10.16.1-linux-x64.tar.gz
Rename the folder after the decompression is complete, rename the folder to node (optional):
Mv node-v10.16.1-linux-x64 / usr/local/node
3. Test whether the installation is successful
Go to the bin directory under the node directory and execute the ls command:
[root@ncd-sc-nginx tool] # cd / usr/local/node/bin/ [root@ncd-sc-nginx bin] # lsnode npm npx [root@ncd-sc-nginx bin] #. / node-vv10.16.1
Configure environment variables
Vim / etc/profile#set for nodejsexport NODE_HOME=/usr/local/nodeexport PATH=$NODE_HOME/bin:$PATH
Compile profile to make the configuration effective
Source / etc/profile
View the version:
Node-version
If the version number is output, the installation is successful.
5 upgrade the node version with the n command
Install the command npm install-g n
Upgrade n latest after installation
Npm install-g nn latest
Now you can use the latest version of node.
Other (optional)
1. Add Taobao image for npm
Npm config set registry https://registry.npm.taobao.org
When you are finished, you can use:
Npm config get registry
View the results of the modification.
2. Use the cnpm of Taobao npm image (the method used in this article)
Because downloads are foreign servers that are slow to drop, we need to use Taobao's npm image cnpm. Execute the command:
Npm install-g cnpm-- registry= https://registry.npm.taobao.org on how to install nodejs in CentOS7 to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.