一、环境准备

1.1 查看系统环境

[root@localhost ~]#  cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@localhost ~]# uname -m
x86_64
[root@localhost ~]# uname -r
3.10.0-862.el7.x86_64

1.2 关闭防火墙和selinux

1.2.1 关闭防火墙

[root@mysql-5 ~]# /bin/systemctl stop firewalld
[root@mysql-5 ~]# /bin/systemctl disable firewalld

1.2.2 关闭selinux

[root@mysql-5 ~]# getenforce                 #查看selinux是否开启
Enforcing #enforcing表示selinux开启的,
[root@mysql-5 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config #修改配置文件,需要重启才后永久关闭
[root@mysql-5 ~]# setenforce 0 #临时关闭selinx
[root@mysql-5 ~]# getenforce #查看是否关闭
Disabled

二、安装epel源

[root@localhost ~]# rpm -ivh http://mirrors.ustc.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm
获取http://mirrors.ustc.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm
准备中... ################################# [100%]
软件包 epel-release-7-12.noarch 已经安装

三、安装nodejs和npm

3.1 安装nodejs和npm

[root@localhost ~]# yum install nodejs -y
已加载插件:fastestmirror
Determining fastest mirrors
epel/x86_64/metalink | 6.3 kB 00:00:05
* base: mirrors.aliyun.com
* city-fan.org: nervion.us.es
* epel: hkg.mirror.rackspace.com
* extras: mirrors.aliyun.com
* updates: mirror-hk.koddos.net
base | 3.6 kB 00:00:00
city-fan.org | 3.0 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/8): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/8): base/7/x86_64/primary_db | 6.1 MB 00:00:03
(3/8): extras/7/x86_64/primary_db | 194 kB 00:00:00
(4/8): epel/x86_64/group_gz | 95 kB 00:00:03
(5/8): updates/7/x86_64/primary_db | 3.0 MB 00:00:02
(6/8): city-fan.org/7/primary_db | 508 kB 00:00:13
(7/8): epel/x86_64/updateinfo | 1.0 MB 00:00:32
(8/8): epel/x86_64/primary_db | 6.8 MB 00:03:40
正在解决依赖关系
--> 正在检查事务
---> 软件包 nodejs.x86_64.1.6.17.1-1.el7 将被 安装
--> 正在处理依赖关系 npm = 1:3.10.10-1.6.17.1.1.el7,它被软件包 1:nodejs-6.17.1-1.el7.x86_64 需要
--> 正在处理依赖关系 libuv >= 1:1.9.1,它被软件包 1:nodejs-6.17.1-1.el7.x86_64 需要
--> 正在处理依赖关系 libuv.so.1()(64bit),它被软件包 1:nodejs-6.17.1-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libuv.x86_64.1.1.38.0-2.el7 将被 安装
---> 软件包 npm.x86_64.1.3.10.10-1.6.17.1.1.el7 将被 安装
--> 解决依赖关系完成 依赖关系解决 =====================================================================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================================================================
正在安装:
nodejs x86_64 1:6.17.1-1.el7 epel 4.7 M
为依赖而安装:
libuv x86_64 1:1.38.0-2.el7 epel 148 k
npm x86_64 1:3.10.10-1.6.17.1.1.el7 epel 2.5 M 事务概要
=====================================================================================================================================================================================
安装 1 软件包 (+2 依赖软件包) 总下载量:7.4 M
安装大小:27 M
Downloading packages:
(1/3): npm-3.10.10-1.6.17.1.1.el7.x86_64.rpm | 2.5 MB 00:00:02
(2/3): libuv-1.38.0-2.el7.x86_64.rpm | 148 kB 00:00:10
nodejs-6.17.1-1.el7.x86_64.rpm FAILED [=======================- ] 1.3 B/s | 2.7 MB 1064:06:38 ETA
https://mirror.yer.az/fedora-epel/7/x86_64/Packages/n/nodejs-6.17.1-1.el7.x86_64.rpm: [Errno 12] Timeout on https://mirror.yer.az/fedora-epel/7/x86_64/Packages/n/nodejs-6.17.1-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
(3/3): nodejs-6.17.1-1.el7.x86_64.rpm | 4.7 MB 00:00:03
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 98 kB/s | 7.4 MB 00:01:16
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 1:libuv-1.38.0-2.el7.x86_64 1/3
正在安装 : 1:nodejs-6.17.1-1.el7.x86_64 2/3
正在安装 : 1:npm-3.10.10-1.6.17.1.1.el7.x86_64 3/3
验证中 : 1:npm-3.10.10-1.6.17.1.1.el7.x86_64 1/3
验证中 : 1:nodejs-6.17.1-1.el7.x86_64 2/3
验证中 : 1:libuv-1.38.0-2.el7.x86_64 3/3 已安装:
nodejs.x86_64 1:6.17.1-1.el7 作为依赖被安装:
libuv.x86_64 1:1.38.0-2.el7 npm.x86_64 1:3.10.10-1.6.17.1.1.el7 完毕!

3.2、查看安装node

[root@localhost ~]# node -v
v6.17.1
[root@localhost ~]# npm -v
3.10.10

提示:这里我们发现安装版本有点低,我们需要在下面升级一下版本

3.3、设置淘宝镜像和安装淘宝cnpm

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

3.4、安装升级node版本工具

[root@localhost ~]# npm install -g n
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
/usr/lib
└── n@6.5.1

3.5、验证n工具能否使用,并查看帮助怎么使用

[root@localhost ~]# n -h

Usage: n [options] [COMMAND] [args]

Commands:

  n                              Display downloaded node versions and install selection
n latest Install the latest node release (downloading if necessary)
n lts Install the latest LTS node release (downloading if necessary)
n <version> Install node <version> (downloading if necessary)
n run <version> [args ...] Execute downloaded node <version> with [args ...]
n which <version> Output path for downloaded node <version>
n exec <vers> <cmd> [args...] Execute command with modified PATH, so downloaded node <version> and npm first
n rm <version ...> Remove the given downloaded version(s)
n prune Remove all downloaded versions except the installed version
n --latest Output the latest node version available
n --lts Output the latest LTS node version available
n ls Output downloaded versions
n ls-remote [version] Output matching versions available for download
n uninstall Remove the installed node and npm Options: -V, --version Output version of n
-h, --help Display help information
-p, --preserve Preserve npm and npx during install of node (requires rsync)
-q, --quiet Disable curl output (if available)
-d, --download Download only
-a, --arch Override system architecture
--all ls-remote displays all matches instead of last 20
--insecure Turn off certificate checking for https requests (may be needed from behind a proxy server)
--use-xz/--no-use-xz Override automatic detection of xz support and enable/disable use of xz compressed node downloads. Aliases: which: bin
run: use, as
ls: list
lsr: ls-remote
rm: -
lts: stable
latest: current Versions: Numeric version numbers can be complete or incomplete, with an optional leading 'v'.
Versions can also be specified by label, or codename,
and other downloadable releases by <remote-folder>/<version> 4.9.1, 8, v6.1 Numeric versions
lts Newest Long Term Support official release
latest, current Newest official release
auto Read version from .n-node-version
boron, carbon Codenames for release streams
and nightly, chakracore-release/latest, rc/10 et al

3.6 升级node到稳定版

[root@localhost ~]# n stable

  installing : node-v12.18.2
mkdir : /usr/local/n/versions/node/12.18.2
fetch : https://nodejs.org/dist/v12.18.2/node-v12.18.2-linux-x64.tar.xz
installed : v12.18.2 (with npm 6.14.5) Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"

3.7、升级npm到最新

[root@localhost ~]# npm install -g npm
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
/usr/local/lib
└── npm@6.14.5

3.8、验证是否是最新稳定版

[root@localhost ~]# node -v
v12.18.2
[root@localhost ~]# npm -v
6.14.5

3.9、n工具指定node版本,命令打包编译

n exec 12 cnpm install

注释:
n:为指定使用的工具
exec:命令使用的方法
12:为node版本
cnpm:执行的工具
install:执行安装命令

四、安装pm2工具

4.1、安装pm2工具

[root@localhost ~]# npm install -g pm2
/usr/local/bin/pm2 -> /usr/local/lib/node_modules/pm2/bin/pm2
/usr/local/bin/pm2-dev -> /usr/local/lib/node_modules/pm2/bin/pm2-dev
/usr/local/bin/pm2-docker -> /usr/local/lib/node_modules/pm2/bin/pm2-docker
/usr/local/bin/pm2-runtime -> /usr/local/lib/node_modules/pm2/bin/pm2-runtime
npm WARN ws@7.2.5 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.2.5 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) + pm2@4.4.0
added 185 packages from 191 contributors in 14.145s

4.2、pm2工具帮助使用

pm2 start app.js  启动app项目

pm2 list 列出由pm2管理的所有进程信息,还会显示一个进程会被启动多少次,因为没处理的异常。

pm2 monit 监视每个node进程的CPU和内存的使用情况

pm2 logs 显示所有进程日志

pm2 stop all 停止所有进程

pm2 restart all 重启所有进程

pm2 reload all 0秒停机重载进程 (用于 NETWORKED 进程)

pm2 stop 0 停止指定的进程

pm2 restart 0 重启指定的进程

pm2 startup 产生 init 脚本 保持进程活着

pm2 web 运行健壮的 computer API endpoint (http://localhost:9615)

pm2 delete 0 杀死指定的进程

pm2 delete all 杀死全部进程

五、安装yarn工具

5.1、安装yarn工具

[root@localhost ~]# npm install -g yarn
/usr/local/bin/yarn -> /usr/local/lib/node_modules/yarn/bin/yarn.js
/usr/local/bin/yarnpkg -> /usr/local/lib/node_modules/yarn/bin/yarn.js
+ yarn@1.22.4
added 1 package in 1.189s

5.2、查看yarn工具帮助

[root@localhost ~]# yarn -h

  Usage: yarn [command] [flags]

  Displays help information.

  Options:

    --cache-folder <path>               specify a custom folder that must be used to store the yarn cache
--check-files install will verify file tree of packages for consistency
--cwd <cwd> working directory to use (default: /root)
--disable-pnp disable the Plug'n'Play installation
--emoji [bool] enable emoji in output (default: false)
--enable-pnp, --pnp enable the Plug'n'Play installation
--flat only allow one version of a package
--focus Focus on a single workspace by installing remote copies of its sibling workspaces.
--force install and build packages even if they were built before, overwrite lockfile
--frozen-lockfile don't generate a lockfile and fail if an update is needed
--global-folder <path> specify a custom folder to store global packages
--har save HAR output of network traffic
--https-proxy <host>
--ignore-engines ignore engines check
--ignore-optional ignore optional dependencies
--ignore-platform ignore platform checks
--ignore-scripts don't run lifecycle scripts
--json format Yarn log messages as lines of JSON (see jsonlines.org)
--link-duplicates create hardlinks to the repeated modules in node_modules
--link-folder <path> specify a custom folder to store global links
--modules-folder <path> rather than installing modules into the node_modules folder relative to the cwd, output them here
--mutex <type>[:specifier] use a mutex to ensure only one yarn instance is executing
--network-concurrency <number> maximum number of concurrent network requests
--network-timeout <milliseconds> TCP timeout for network requests
--no-bin-links don't generate bin links when setting up packages
--no-default-rc prevent Yarn from automatically detecting yarnrc and npmrc files
--no-lockfile don't read or generate a lockfile
--non-interactive do not show interactive prompts
--no-node-version-check do not warn when using a potentially unsupported Node version
--no-progress disable progress bar
--offline trigger an error if any required dependencies are not available in local cache
--otp <otpcode> one-time password for two factor authentication
--prefer-offline use network only if dependencies are not available in local cache
--preferred-cache-folder <path> specify a custom folder to store the yarn cache if possible
--prod, --production [prod]
--proxy <host>
--pure-lockfile don't generate a lockfile
--registry <url> override configuration registry
-s, --silent skip Yarn console logs, other types of logs (script output) will be printed
--scripts-prepend-node-path [bool] prepend the node executable dir to the PATH in scripts
--skip-integrity-check run install without checking if node_modules is installed
--strict-semver
--update-checksums update package checksums from current repository
--use-yarnrc <path> specifies a yarnrc file that Yarn should use (.yarnrc only, not .npmrc) (default: )
-v, --version output the version number
--verbose output verbose messages on internal operations
-h, --help output usage information
Commands:
- access
- add
- audit
- autoclean
- bin
- cache
- check
- config
- create
- exec
- generate-lock-entry / generateLockEntry
- global
- help
- import
- info
- init
- install
- licenses
- link
- list
- login
- logout
- node
- outdated
- owner
- pack
- policies
- publish
- remove
- run
- tag
- team
- unlink
- unplug
- upgrade
- upgrade-interactive / upgradeInteractive
- version
- versions
- why
- workspace
- workspaces Run `yarn help COMMAND` for more information on specific commands.
Visit https://yarnpkg.com/en/docs/cli/ to learn more about Yarn.

centos7 yum 安装nodejs、npm、cnpm、pm2、yarn的更多相关文章

  1. CentOS7.6安装Nodejs(Npm)

    官网下载地址:https://nodejs.org/en/download/ 第一步:软件下载安装 进行安装目录:cd /opt/software (如果目录不存在,请先创建目录) 下载二进制包:wg ...

  2. centOS7下 安装nodejs+nginx+mongodb+pm2部署vue项目

    一.购买服务器并远程连接 1.购买服务器和域名 可以选择阿里云或者是其他的厂商的服务器.然后会获得服务器ip地址,用户名和密码. 购买域名,将域名绑定到ip地址上. 2.下载xshell,winscp ...

  3. 在centos7中安装nodejs(npm )

    我当前使用的是Centos7 首先在官网查看当前最新的版本 https://nodejs.org/dist/ 我现在最新的是 https://nodejs.org/dist/latest-v10.x/ ...

  4. CentOS7.5安装nodejs 转

    CentOS7.5安装nodejs CentOS安装NodeJS 在CentOS下安装NodeJS有以下几种方法.使用的CentOS版本为7.2.CentOS其他版本的NodeJS安装大同小异,也可以 ...

  5. CentOS7 yum 安装git

    1.查看系统是否已经安装git git --version 2.CentOS7 yum 安装git yum install -y git 3.安装成功 4.卸载git yum remove git

  6. Linux系统使用yum安装nodejs

    先执行: yum install \ http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 再执行: su ...

  7. [转帖]Centos7 yum安装Chrome浏览器

    Centos7 yum安装Chrome浏览器 https://www.cnblogs.com/ianduin/p/8727333.html以及https://blog.csdn.net/libaine ...

  8. centos7 yum安装配置redis 并设置密码

    原文:https://www.cnblogs.com/fanlinglong/p/6635828.html centos7 yum安装配置redis 并设置密码 1.设置Redis的仓库地址 yum ...

  9. centos7 yum安装遇到报错:Head V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEYer

    centos7 yum安装时遇到错误:Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY 无法安装时,可按如下方法解决: This mini ...

随机推荐

  1. [业界方案] 用SOFATracer学习分布式追踪系统Opentracing

    [业界方案] 用SOFATracer学习分布式追踪系统Opentracing 目录 [业界方案] 用SOFATracer学习分布式追踪系统Opentracing 0x00 摘要 0x01 缘由 &am ...

  2. C012:颠倒显示两位数

    代码: #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int original; do{ printf(&q ...

  3. 滴滴AR实景导航背后的技术

    桔妹导读:机场.商场.火车站等大型室内场所内GPS信号不稳定.室内面积大.路线复杂.用户判断方向难等问题,给在大型场所内发单的乘客找上车点带来了很大的挑战,用户急需一种操作简单.交互友好的引导功能.本 ...

  4. 如何编写一个简单的Linux驱动(二)——完善设备驱动

    前期知识 1.如何编写一个简单的Linux驱动(一)——驱动的基本框架 2.如何编写一个简单的Linux驱动(二)——设备操作集file_operations 前言 在上一篇文章中,我们编写设备驱动遇 ...

  5. oracle之同义词

    同义词 从字面上理解就是别名的意思,和视图的功能类似.就是一种映射关系. 14.1 私有同义词; 一般是普通用户自己建立的同义词,创建者需要create synonym 权限. sys:SQL> ...

  6. 第1课 - make和makefile

    第1课 - make 和 makefile 1. make make 是一个应用程序,位于 /usr/bin/make 目录下,make 有如下的功能: (1)解析源程序之间的依赖关系 (2)根据依赖 ...

  7. spyder如何切换python虚拟环境?

    2020/5/29 在anaconda下创建了很多个python虚拟环境,现在我想使用 spyder 运行python程序, 并且使用其中某一个虚拟环境,方法如下: 首先要知道 Anaconda自带的 ...

  8. defer 延迟调用

    1. 延迟调用 defer 的用法很简单,只要在后面跟一个函数的调用,就能实现将这个  xxx 函数的调用延迟到当前函数执行完后再执行. defer xxx()   这是一个很简单的例子,可以很快帮助 ...

  9. Vulkan在Android使用Compute shader

    oeip 相关功能只能运行在window平台,想移植到android平台,暂时选择vulkan做为图像处理,主要一是里面有单独的计算管线且支持好,二是熟悉下最新的渲染技术思路. 这个 demo(git ...

  10. 被产品经理怼了,线上出Bug为啥你不知道

    前言 前几天跟读者聊天,他说被产品经理给怼了.原因是线上出 Bug 了,最后是客户反馈才知道的. 我就问他:你们是不是没做监控? 读者:我们是刚成立的创业团队,目前最重要的就是堆功能,很多基础设施都没 ...