Install Node.js on Linux system

Related shell command reference

1. CentOS install Node.js

User: root

1.1 Node.js download and upload

View system digits

uname -a

Insert picture description here
The view here is 64-bit.

Download link : Node.js Chinese website
Insert picture description here
Modify the downloaded compressed package name as: nodejs.tar.xz

Insert picture description here

Switch to the directory where you want to install node and upload nodejs.tar.xz

cd usr/software 
rz -y

Insert picture description here
Insert picture description here

Download Node.js in this step, which can also be achieved by using wget

wget https://npm.taobao.org/mirrors/node/v11.7.0/node-v11.7.0-linux-x64.tar.xz

ps:
Linux wget is a tool for downloading files, used on the command line. It is an indispensable tool for Linux users, especially for network administrators, who often have to download some software or restore backups from a remote server to a local server. If we use a virtual host, we can only download from the remote server to our computer disk first, and then upload it to the server using the ftp tool. This is a waste of time and energy. But for Linux VPS, it can be downloaded directly to the server without going through the upload step. The wget tool is small in size but complete in function. It supports breakpoint download function, supports FTP and HTTP download methods, supports proxy server and is easy to set up and easy to
install.

yum -y install wget

1.2 Unzip nodejs.tar.xz and rename it

tar -xvf nodejs.tar.xz

Insert picture description here

mv node-v14.15.4-linux-x64 nodejs

Insert picture description here

1.3 Establishing a soft connection to become global
We see that the bin directory points to user/bin:
Insert picture description here

At this time, using node -v cannot display the version number of node, because the node command cannot be used globally, and a soft link needs to be established to make it global.
Global variables need to be configured under similar windows.
The bin directory of the unzipped file contains commands such as node and npm. We can use the ln command to set up the soft connection:
Insert picture description here

ln -s /usr/software/nodejs/bin/node /usr/bin/
ln -s /usr/software/nodejs/bin/npm /usr/bin/

After creation, it will point to /user/bin/node and /user/bin/npm;

1.4 Check whether the installation is successful

node -v
npm -v

Insert picture description here
Just see the version information displayed

1.5 Installation of other tools

1.5.1 Install cnpm Taobao mirror

npm install -g cnpm --registry=https://registry.npm.taobao.org

Create soft link

ln -s /usr/software/nodejs/bin/cnpm /usr/bin/

1.5.2 Install pm2

PM2 is a node process management tool, which can be used to simplify many tedious tasks of node application management, such as performance monitoring, automatic restart, load balancing, etc., and it is very simple to use.

cnpm install -g pm2

Create soft link

ln -s /usr/software/nodejs/bin/pm2 /usr/bin/

Recommended reading: Install Nginx on Linux

Guess you like

Origin blog.csdn.net/ZYS10000/article/details/113514546