Recently, during the server migration, I also encountered some problems in installing the Node environment. I wanted to install a lower version, but when I upgraded the NPM, I reported an errorNPM WARN NPM NPM does not support Node.js V8.11.1NPM is not supported on node versions. So there is no way, do it yourself, first uninstall, then install.

uninstall

yum remove nodejs npm -yUsing this command to uninstall, you will find it useless



Results:



Since I can’t uninstall it, I can always delete the file.

Using the commandrm -rfdeletenodeFolder and soft connection (do not have soft connection can not delete)

The node-v package command does not exist

The installation

I usually install software in /usr/local, so use CD /usr/local to run the following command.

  • Wget HTTP: / / https://nodejs.org/dist/v16.4.0/node-v16.4.0-linux-x64.tar.xzTo download the Node package, note that you need to download the node package16.4.0—–> Switch to a newer package, I am currently using the latest version, but it may not be the latest version later.
  • Xz - d node - v16.4.0 - Linux - x64. Tar. Xz:.xzThe package —–> decompress into.tarThe package

    The tar xf node - v16.4.0 - Linux - x64. Tar:.tarThe package —–> decompress into folders
  • Cp -r node - v16.4.0 - Linux - x64 / usr/local /: Moves the directory tousr/localUnder the directory (optional, the custom of installing your own installation package is also done here to prepare for the soft connection below)
  • Ln -s/usr/local/node - v16.4.0 - Linux - x64 / bin/node/usr/local/bin/node: Configures node soft connections

    Ln -s/usr/local/node - v16.4.0 - Linux - x64 / bin/NPM/usr/local/bin/NPM: Configures the NPM soft connection

    Ln -s/usr/local/node - v16.4.0 - Linux - x64 / bin/NPX/usr/local/bin/NPX: Configures the NPX soft connection

And then you usenode-v, npm -vThe results are as follows:

See this is node installed, NPM is also according to the good, and can be used globally

The installationpm2To daemon

Using the commandnpm install -g pm2Install pM2 globally, and once installed, configure the soft connection to take effect on the command line.

Ln -s/usr/local/node - v16.4.0 - Linux - x64 / bin/pm2 / usr/local/bin/pm2: Configures the PM2 soft connection

The following result is installed:

  • pm2 list: Viewing processes
  • pm2 start index.js: Starts a Node service
  • pm2 stop/reload/restart/delete alL: Stop/reload/restart/delete all processes
  • pm2 stop/reload/restart/delete 0: Stop, reload, restart, or delete the process whose process is 0 in the PM2 process list
  • pm2 logs [--raw]: Displays logs of all processes
  • pm2 flush: Clears all log files
  • ‘pm2 reloadLogs: Reload all logs

You can view the list after you start the process

This article uses the article synchronization assistant to synchronize