CentOS 6.X 安裝Node.js

徐子函
徐子函
Aug 31, 2018 · 2 min read

安裝Node.js

yum install -y gcc-c++ make

為了避免太多錯誤的麻煩,最好選擇穩定版本

最新版本

curl -sL https://rpm.nodesource.com/setup_10.x | sudo -E bash -

穩定版本

curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash -

再來利用yum開始安裝

sudo yum install nodejs

安裝完成後,查看Node.js還有NPM的版本:

node -v

會返回如下版本信息:

v8.11.4

然後查看npm的版本信息:

npm -v

會返回如下版本信息:

5.6.0

檢查是否安裝成功

先新增一個demo_server.js檔案

vim demo_server.js

內容為:

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Welcome Node.js');
}).listen(3001, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3001/');

然後執行它:

node -- inspect-brk demo_server.js

若看到以下畫面,則表示安裝成功

Debugger listening on ws://127.0.0.1:9229/3d97df7b-a963–4c2c-b15c-bdf1a42d8e29
For help see https://nodejs.org/en/docs/inspector
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade