There are several ways to install NodeJs:
The first one: The easiest way is to use the yum command. Unfortunately, when I use it now, I find that there is no nodejs in the mirror; so this method is abandoned;
The second: go to the official website to download the source code, and then compile it yourself; there may be problems during the compilation process, and this method is also abandoned if it is troublesome;
The third method: go to the official website to directly download the compiled binary file, which is the most convenient; we use the third method;
Go to the official website first: https://nodejs.org/en/download/
We are centos 64-bit, so right-click the copy download address in the red circle:
https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-x64.tar.xz
We are going to install nodejs under usr/local
So first cd /usr/local/ into the local directory
Then
wget
https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-x64.tar.xzDownload the tarball
xz file we need to decompress
tar -xJf node-v8.9.1-linux-x64.tar.xz
Then we configure the environment variables:
vi /etc/profile
Open
Add at the end:
export NODE_HOME=/usr/local/node-v8.9.1-linux-x64
export PATH=$NODE_HOME/bin:$PATH
After adding, save;
Then execute source /etc/profile to make the environment variable take effect;
Here, let’s talk about the old version of nodejs, which does not come with the npm tool (NPM is a package management tool installed with NodeJS, which can solve many problems in NodeJS code deployment). In the past, it had to be downloaded and installed separately, but now the new version has its own npm so no need to install it again;
Let's verify:
[root @ bogon node-v8.9.1-linux-x64] # node -v
v8.9.1
[root@bogon node-v8.9.1-linux-x64]# npm -v
5.5.1
The installation is OK;