CENTOS安装NODE.JS环境(以编译ARIANG为例)
导读
1、安装依赖工具yum install git
2、下载软件包mkdir -p /appserver/software
cd /appserver/software
wget https://nodejs.org/dist/v12.14.1/node-v12.14.1-linux-x64.tar.xz
mkdir -p /usr/local/lib/nodejs
tar -xJvf node-v12.14.1-linux-x64.tar.xz -C /usr/local/lib/nodejs
3、编辑/etc/profilevi /etc/profile
# Nodejs
VERSION=v12.14.1
DISTRO=linux-x64
export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
4、使设置生效source /etc/profile
5、查看版本node -v
npm version
npx -v
6、测试
ariaNg从源代码构建,需要依赖于node.js、NPM、Gulpcd /tmp
wget https://github.com/mayswind/AriaNg/archive/1.1.4.tar.gz
tar -zxvf 1.1.4.tar.gz
cd AriaNg-1.1.4
npm install
npm install gulp
./node_modules/.bin/gulp -v
./node_modules/.bin/gulp clean build
编译后的生成文件在dist目录内
7、说明
1)npm install在node_modules目录内下载了依赖包npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 1265 packages from 794 contributors and audited 7957 packages in 70.56s
found 79 vulnerabilities (4 low, 11 moderate, 64 high)
run npm audit fix to fix them, or npm audit for details
2)npm install gulp用于安装gulp命令npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated natives@1.1.6: This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs@4.x.
npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ gulp@3.9.1
updated 7 packages and audited 7957 packages in 42.521s
found 79 vulnerabilities (4 low, 11 moderate, 64 high)
run npm audit fix to fix them, or npm audit for details
3)./node_modules/.bin/gulp -v[09:02:03] CLI version 3.9.1
[09:02:03] Local version 3.9.1
4)./node_modules/.bin/gulp clean build[09:24:41] Using gulpfile /tmp/AriaNg-1.1.4/gulpfile.js
[09:24:41] Starting 'clean'…
[09:24:41] Starting 'build'…
[09:24:41] Starting 'lint'…
[09:25:00] Finished 'clean' after 20 s
[09:25:06] Finished 'lint' after 25 s
[09:25:06] Starting 'prepare-fonts'…
[09:25:10] Finished 'prepare-fonts' after 4.32 s
[09:25:10] Starting 'process-fonts'…
[09:25:10] Finished 'process-fonts' after 21 ms
[09:25:10] Starting 'prepare-langs'…
[09:25:12] Finished 'prepare-langs' after 1.14 s
[09:25:12] Starting 'process-langs'…
[09:25:12] Finished 'process-langs' after 5.56 ms
[09:25:12] Starting 'prepare-styles'…
[09:25:54] Starting 'prepare-scripts'…
[09:26:02] Starting 'prepare-views'…
Browserslist: caniuse-lite is outdated. Please run next command npm update
[09:26:29] Finished 'prepare-scripts' after 34 s
[09:26:30] Finished 'prepare-styles' after 1.3 min
[09:26:31] Finished 'prepare-views' after 29 s
[09:26:31] Starting 'prepare-html'…
[09:29:05] Finished 'prepare-html' after 2.57 min
[09:29:05] Starting 'process-html'…
[09:29:05] Finished 'process-html' after 4.72 ms
[09:29:05] Starting 'process-assets'…
[09:29:05] Finished 'process-assets' after 98 ms
[09:29:05] Starting 'process-manifest'…
[09:29:14] Finished 'process-manifest' after 8.75 s
[09:29:14] Starting 'process-full-extras'…
[09:29:15] Finished 'process-full-extras' after 702 ms
[09:29:15] Starting 'info'…
[09:29:17] build all files 994 kB (gzipped)
[09:29:17] Finished 'info' after 2.48 s
[09:29:17] Finished 'build' after 4.6 min
PS:如果报错ReferenceError: primordials is not defined,最新版有兼容问题,将nods.js更换成v11.15.0版本
PS2:如果Browserslist: caniuse-lite is outdated. Please run next command npm update
,可以先执行npm update,再重新编译
5)npm:是随同NodeJS一起安装的包管理工具
6)gulp:是前端开发过程中对代码进行构建的工具
7)npx:临时安装可执行依赖包,不用全局安装
8)package.json和gulpfile.js
package.json是nodejs项目的配置文件,gulpfile.js是前端构建工具gulp的配置文件,使用gulp需要安装nodejs环境