MEAN 以 JavaScript 貫穿全棧,安裝過程依賴 npm、Git、Gulp/Bower、mean-cli,網路教學版本落差大、易踩坑。本文記錄在 Ubuntu Kylin 15.05 成功啟動的完整步驟與關鍵避坑點。
sudo apt-get update sudo apt-get install -y nodejs npm git mongodb
註:Ubuntu 官方倉庫 nodejs 版本較舊,生產建議用 NodeSource PPA 或 nvm 安裝 LTS 版。
sudo npm install -g gulp bower mean-cli
gulp:建構腳本(對應 Ant/Gradle)。bower:前端套件管理(現多改用 npm/yarn)。mean-cli:MEAN 專案脚手架與管理指令。mkdir ~/MEANProject && cd ~/MEANProject mean init testApp
phantomjs-1.9.8-linux-x86_64.tar.bz2,若下載失敗請手動放入 /tmp 對應目錄。cd testApp && npm install
常見錯誤與對策:
| 錯誤 | 原因 | 對策 |
|---|---|---|
| git clone timeout / SSL error | GitHub 連線不穩 | 設定 git config --global url."https://".insteadOf git:// 或用 VPN/鏡像源 |
| phantomjs 下載失敗 | 二進位檔較大易斷點 | 預先下載放入 ~/.phantomjs 或 /tmp 指定路徑 |
| Cannot find module 'express-validator' | 相依未正確安裝 | 刪除 node_modules 重跑 npm install,確保 gulp 先裝好 |