Node.js 是运行在服务端的 JavaScript, 是基于 Chrome JavaScript V8 引擎建立的平台。
任务大纲
1、安装 Node.js 环境(耗时:5min ~ 10min)
2、配置和使用 npm(耗时:8min ~ 10min)
一、安装 Node.js 环境
Node.js 是运行在服务端的 JavaScript, 是基于 Chrome JavaScript V8 引擎建立的平台。
1、下载并安装 Node.js
下载最新的稳定版 v6.10.3 到本地
wget https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-x64.tar.xz
下载完成后, 将其解压
tar xvJf node-v6.10.3-linux-x64.tar.xz
将解压的 Node.js 目录移动到 /usr/local 目录下
mv node-v6.10.3-linux-x64 /usr/local/node-v6
配置 node 软链接到 /bin 目录
ln -s /usr/local/node-v6/bin/node /bin/node
二、配置和使用 npm
1、配置 npm
npm 是 Node.js 的包管理和分发工具。它可以让 Node.js 开发者能够更加轻松的共享代码和共用代码片段
下载 node 的压缩包中已经包含了 npm , 我们只需要将其软链接到 bin 目录下即可
ln -s /usr/local/node-v6/bin/npm /bin/npm
2、配置环境变量
将 /usr/local/node-v6/bin 目录添加到 $PATH 环境变量中可以方便地使用通过 npm 全局安装的第三方工具
echo 'export PATH=/usr/local/node-v6/bin:$PATH' >> /etc/profile
生效环境变量
source /etc/profile
3、使用 npm
通过 npm 安装进程管理模块 forever
npm install forever -g
4、完成实验
恭喜!您已经成功完成了搭建 Node.js 环境的实验任务。
操作日志
[root@VM_175_27_centos ~]# wget https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-x64.tar.xz
...
... 省略下载日志
...
[root@VM_175_27_centos ~]# tar xvJf node-v6.10.3-linux-x64.tar.xz
...
... 省略解压日志
...
[root@VM_175_27_centos ~]#
[root@VM_175_27_centos ~]# mv node-v6.10.3-linux-x64 /usr/local/node-v6
[root@VM_175_27_centos ~]# ln -s /usr/local/node-v6/bin/node /bin/node
[root@VM_175_27_centos ~]# ln -s /usr/local/node-v6/bin/npm /bin/npm
tc/profile75_27_centos ~]# echo 'export PATH=/usr/local/node-v6/bin:$PATH' >> /e
[root@VM_175_27_centos ~]# source /etc/profile
[root@VM_175_27_centos ~]# echo $PATH
/usr/local/node-v6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@VM_175_27_centos ~]# npm install forever -g
/usr/local/node-v6/bin/forever -> /usr/local/node-v6/lib/node_modules/forever/bin/forever
/usr/local/node-v6/lib
└─┬ forever@0.15.3
├─┬ cliff@0.1.10
│ ├── colors@1.0.3
│ └── eyes@0.1.8
├── clone@1.0.2
├── colors@0.6.2
├─┬ flatiron@0.4.3
│ ├─┬ broadway@0.3.6
│ │ ├── cliff@0.1.9
│ │ └── winston@0.8.0
│ ├── director@1.2.7
│ ├── optimist@0.6.0
│ └─┬ prompt@0.2.14
│ ├─┬ read@1.0.7
│ │ └── mute-stream@0.0.7
│ └── revalidator@0.1.8
├─┬ forever-monitor@1.7.1
│ ├─┬ chokidar@1.7.0
│ │ ├─┬ anymatch@1.3.2
│ │ │ ├─┬ micromatch@2.3.11
│ │ │ │ ├─┬ arr-diff@2.0.0
│ │ │ │ │ └── arr-flatten@1.1.0
│ │ │ │ ├── array-unique@0.2.1
│ │ │ │ ├─┬ braces@1.8.5
│ │ │ │ │ ├─┬ expand-range@1.8.2
│ │ │ │ │ │ └─┬ fill-range@2.2.3
│ │ │ │ │ │ ├── is-number@2.1.0
│ │ │ │ │ │ ├── isobject@2.1.0
│ │ │ │ │ │ ├─┬ randomatic@1.1.7
│ │ │ │ │ │ │ ├─┬ is-number@3.0.0
│ │ │ │ │ │ │ │ └── kind-of@3.2.2
│ │ │ │ │ │ │ └── kind-of@4.0.0
│ │ │ │ │ │ └── repeat-string@1.6.1
│ │ │ │ │ ├── preserve@0.2.0
│ │ │ │ │ └── repeat-element@1.1.2
│ │ │ │ ├─┬ expand-brackets@0.1.5
│ │ │ │ │ └── is-posix-bracket@0.1.1
│ │ │ │ ├── extglob@0.3.2
│ │ │ │ ├── filename-regex@2.0.1
│ │ │ │ ├─┬ kind-of@3.2.2
│ │ │ │ │ └── is-buffer@1.1.6
│ │ │ │ ├─┬ object.omit@2.0.1
│ │ │ │ │ ├─┬ for-own@0.1.5
│ │ │ │ │ │ └── for-in@1.0.2
│ │ │ │ │ └── is-extendable@0.1.1
│ │ │ │ ├─┬ parse-glob@3.0.4
│ │ │ │ │ ├── glob-base@0.3.0
│ │ │ │ │ └── is-dotfile@1.0.3
│ │ │ │ └─┬ regex-cache@0.4.4
│ │ │ │ └─┬ is-equal-shallow@0.1.3
│ │ │ │ └── is-primitive@2.0.0
│ │ │ └─┬ normalize-path@2.1.1
│ │ │ └── remove-trailing-separator@1.1.0
│ │ ├── async-each@1.0.1
│ │ ├── glob-parent@2.0.0
│ │ ├── inherits@2.0.3
│ │ ├─┬ is-binary-path@1.0.1
│ │ │ └── binary-extensions@1.10.0
│ │ ├─┬ is-glob@2.0.1
│ │ │ └── is-extglob@1.0.0
│ │ └─┬ readdirp@2.1.0
│ │ ├── graceful-fs@4.1.11
│ │ ├─┬ readable-stream@2.3.3
│ │ │ ├── core-util-is@1.0.2
│ │ │ ├── isarray@1.0.0
│ │ │ ├── process-nextick-args@1.0.7
│ │ │ ├── safe-buffer@5.1.1
│ │ │ ├── string_decoder@1.0.3
│ │ │ └── util-deprecate@1.0.2
│ │ └── set-immediate-shim@1.0.1
│ ├─┬ minimatch@3.0.4
│ │ └─┬ brace-expansion@1.1.8
│ │ ├── balanced-match@1.0.0
│ │ └── concat-map@0.0.1
│ └─┬ ps-tree@0.0.3
│ └─┬ event-stream@0.5.3
│ └── optimist@0.2.8
├─┬ nconf@0.6.9
│ ├── async@0.2.9
│ ├── ini@1.3.4
│ └── optimist@0.6.0
├─┬ nssocket@0.5.3
│ ├── eventemitter2@0.4.14
│ └── lazy@1.0.11
├── object-assign@3.0.0
├─┬ optimist@0.6.1
│ ├── minimist@0.0.10
│ └── wordwrap@0.0.3
├── path-is-absolute@1.0.1
├─┬ prettyjson@1.2.1
│ ├── colors@1.1.2
│ └── minimist@1.2.0
├─┬ shush@1.0.0
│ ├─┬ caller@0.0.1
│ │ └─┬ tape@2.3.3
│ │ ├── deep-equal@0.1.2
│ │ ├── defined@0.0.0
│ │ ├── jsonify@0.0.0
│ │ ├── resumer@0.0.0
│ │ └── through@2.3.8
│ └── strip-json-comments@0.1.3
├── timespan@2.3.0
├─┬ utile@0.2.1
│ ├── async@0.2.10
│ ├── deep-equal@1.0.1
│ ├── i@0.3.6
│ ├─┬ mkdirp@0.5.1
│ │ └── minimist@0.0.8
│ ├── ncp@0.4.2
│ └─┬ rimraf@2.6.2
│ └─┬ glob@7.1.2
│ ├── fs.realpath@1.0.0
│ ├─┬ inflight@1.0.6
│ │ └── wrappy@1.0.2
│ └── once@1.4.0
└─┬ winston@0.8.3
├── cycle@1.0.3
├── isstream@0.1.2
├── pkginfo@0.3.1
└── stack-trace@0.0.10
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/forever/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
[root@VM_175_27_centos ~]#根据腾讯实验室操作总结:https://cloud.tencent.com/developer/labs/lab/10040
未经允许请勿转载:程序喵 » Linux 搭建 Node.js 环境
程序喵