在本機執行 Gemma 4 代表你的資料永遠不會離開你的電腦。零 API 費用、無速率限制、完全隱私。本教學教你如何在 5 分鐘內用 Ollama 跑起 Gemma 4。
你需要什麼
- 至少 8GB 記憶體的電腦(推薦 16GB 以執行更大的模型)
- macOS、Windows 或 Linux 系統
- 約 2-5GB 可用磁碟空間(取決於模型大小)
第一步:安裝 Ollama
前往 ollama.com 下載適合你作業系統的安裝包。
macOS:
# 或透過 Homebrew 安裝
brew install ollamaLinux:
curl -fsSL https://ollama.com/install.sh | shWindows: 從 ollama.com/download 下載安裝包。
第二步:執行 Gemma 4
安裝好 Ollama 後,執行 Gemma 4 只需一行指令:
ollama run gemma4就這麼簡單。Ollama 會自動下載模型並啟動互動式對話。其他下載方式(Hugging Face、LM Studio、Kaggle)可以看下載安裝完整攻略。
選擇合適的模型大小
Gemma 4 有四種規格,依需求選擇:
| 模型 | 參數量 | 記憶體需求 | 適用情境 | 指令 |
|---|---|---|---|---|
| E2B | 20億 | ~4GB | 手機、輕量任務 | ollama run gemma4:e2b |
| E4B | 40億 | ~6GB | 筆電、日常使用 | ollama run gemma4:e4b |
| 26B MoE | 260億 | ~16GB | 最佳性價比 | ollama run gemma4:26b |
| 31B Dense | 310億 | ~20GB | 最高品質 | ollama run gemma4:31b |
建議: 如果你有一台現代筆電,從 E4B 開始。它在速度和品質之間取得了最佳平衡。不知道選哪個?看看模型選擇指南。
第三步:不同情境的使用方法
文字聊天
ollama run gemma4
>>> 用簡單的話解釋一下量子計算程式碼產生
ollama run gemma4
>>> 寫一個 Python 函式,按字典的某個鍵對列表排序圖片理解(多模態)
Gemma 4 可以分析圖片:
ollama run gemma4
>>> 描述這張圖片:/path/to/image.jpg使用 API
Ollama 還提供本機 API,位址為 http://localhost:11434:
curl http://localhost:11434/api/generate -d '{
"model": "gemma4",
"prompt": "什麼是機器學習?"
}'效能最佳化技巧
- 關閉其他應用程式 — 為模型騰出更多記憶體
- 使用量化模型 — Ollama 預設提供量化版本,速度更快
- GPU 加速 — 如果有 NVIDIA GPU,Ollama 會自動使用
- 調整上下文長度 — 如需更長對話,設定
/set parameter num_ctx 8192
Gemma 4 本機執行 vs 雲端 API
| 特性 | Gemma 4 本機(Ollama) | 雲端 API(ChatGPT、Gemini) |
|---|---|---|
| 費用 | 永久免費 | 按 token 付費 |
| 隱私 | 100% 本機 | 資料傳送到伺服器 |
| 速度 | 取決於硬體 | 通常更快 |
| 網路 | 不需要 | 必須連網 |
| 速率限制 | 無 | 有 |
| 可客製化 | 完全掌控 | 有限 |
常見問題
「記憶體不足」 — 試試更小的模型:ollama run gemma4:e2b
回應很慢 — 確保沒有其他吃資源的應用程式在執行。檢查 GPU 是否在使用:ollama ps
找不到模型 — 更新 Ollama:ollama update,然後重試。
更多問題的詳細解決方案,看Gemma 4 常見問題排查。
下一步
- 在我們的 首頁 比較 Gemma 4 不同模型
- 試試 LM Studio 的圖形化介面
- 探索 Google AI Studio 的雲端存取
Gemma 4 由 Google DeepMind 開發,採用 Apache 2.0 授權發布。本教學由 Gemma 4 AI 社群提供。
Stop reading. Start building.
~/gemma4 $ Get hands-on with the models discussed in this guide. No deployment, no friction, 100% free playground.
Launch Playground />


