centos7 yum 安装nodejs、npm、cnpm、pm2、yarn
一、环境准备
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的更多相关文章
- CentOS7.6安装Nodejs(Npm)
官网下载地址:https://nodejs.org/en/download/ 第一步:软件下载安装 进行安装目录:cd /opt/software (如果目录不存在,请先创建目录) 下载二进制包:wg ...
- centOS7下 安装nodejs+nginx+mongodb+pm2部署vue项目
一.购买服务器并远程连接 1.购买服务器和域名 可以选择阿里云或者是其他的厂商的服务器.然后会获得服务器ip地址,用户名和密码. 购买域名,将域名绑定到ip地址上. 2.下载xshell,winscp ...
- 在centos7中安装nodejs(npm )
我当前使用的是Centos7 首先在官网查看当前最新的版本 https://nodejs.org/dist/ 我现在最新的是 https://nodejs.org/dist/latest-v10.x/ ...
- CentOS7.5安装nodejs 转
CentOS7.5安装nodejs CentOS安装NodeJS 在CentOS下安装NodeJS有以下几种方法.使用的CentOS版本为7.2.CentOS其他版本的NodeJS安装大同小异,也可以 ...
- CentOS7 yum 安装git
1.查看系统是否已经安装git git --version 2.CentOS7 yum 安装git yum install -y git 3.安装成功 4.卸载git yum remove git
- Linux系统使用yum安装nodejs
先执行: yum install \ http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 再执行: su ...
- [转帖]Centos7 yum安装Chrome浏览器
Centos7 yum安装Chrome浏览器 https://www.cnblogs.com/ianduin/p/8727333.html以及https://blog.csdn.net/libaine ...
- centos7 yum安装配置redis 并设置密码
原文:https://www.cnblogs.com/fanlinglong/p/6635828.html centos7 yum安装配置redis 并设置密码 1.设置Redis的仓库地址 yum ...
- centos7 yum安装遇到报错:Head V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEYer
centos7 yum安装时遇到错误:Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY 无法安装时,可按如下方法解决: This mini ...
随机推荐
- webpack跨域配置处理
打开config->index.js 配置其中的proxyTable module.exports = { dev: { // Paths assetsSubDirectory: 'static ...
- codewars贪吃蛇算法题目
有这样一个题目: Given an n x n array, return the array elements arranged from outermost elements to the mid ...
- stack 数据结构
栈定义 栈:后进先出(永远从栈顶取元素)LIFO last-in-first-out 栈实现 class Stack { constructor() { this.items = [] this. ...
- Eclipse获取工作空间跟运行空间
System.out.println(System.getProperty("user.dir"));//当前工作空间 System.out.println(Platform.ge ...
- web测试——弱网测试、暂停页面执行
1.弱网测试: 2.暂停页面执行 1.js代码:可以直接在页面上打断点 缺点:需要看懂前端的代码 2.点击暂停按钮,如下图,再次点击,可继续运行
- Aggressive cows(POJ 2456)
原题如下: Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20524 Accepted: ...
- 规则引擎在IoT的重要性?
前言 物联网的强大功能主要来自于它使我们能够实时做出更准确的决策的能力,这些在通知.自动化和预测性维护上都有所体现.因此我们需要能对实时数据进行实时响应的工具,答案就是规则引擎.规则引擎可以通过摄取实 ...
- 一篇文章说清楚TDengine的FQDN
TDengine2.0以后需要使用FQDN来进行访问.小朋友,你是否有很多小问号:什么是FQDN,为什么要配置FQDN,如何配置FQDN.我们今天来简单讲一下.心急的小伙伴,可以直接跳转到配置章节. ...
- 360 Atlas生产环境使用心得
一.Atlas介绍 Atlas是360开源的一个Mysql Proxy,以下是官方介绍: Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目 ...
- magento首页
访问首页的时候,路径时没有的,magneto会获取站点的默认路径Mage_Core_Controller_Varien_Router_Standard::match if ($path) { ...