Systemd 與 D-Bus 整合
Ghostty 內建對 D-Bus 啟用與 `systemd` 服務的支援, 可按需求啟動並即時建立新視窗。
若正確安裝1,Ghostty 會附帶數個 systemd 單元。 透過這些 systemd 單元執行 Ghostty 是建議的方式。Ghostty 的 systemd 整合提供的兩個最重要的好處是:即時啟動2與集中 日誌記錄。
如果你的系統有 systemd,並且你透過系統套件或
如說明文件所述 安裝了 Ghostty,那麼 Ghostty 應該
直接可用。除非你想理解這一切如何運作或
需要排解問題,否則無須閱讀本說明文件。
Important
Ghostty 不需要 systemd 即可執行。你可以在任何沒有 systemd 的系統上直接執行
ghostty二進位檔,Ghostty 依然 正常運作。但 你會 失去 本頁 說明文件 所提到的 好處。
Important
在設定檔中使用
class可能干擾systemd單元檔 或 D-Bus 啟用的正常運作。我們建議從設定 檔中移除它們,只在需要時透過命令列 明確使用。
可以設定 Ghostty 在登入時於背景啟動,使將來建立新視窗的
請求極為快速。這透過 systemd 啟用
Ghostty 使用者服務來完成:
systemctl enable --user app-com.mitchellh.ghostty.service
這會將你的系統設定為登入時啟動 Ghostty,但不建立任何視窗。 任何啟動延遲都會被登入後系統完成其餘設定所需的時間 「隱藏」。
在設定中加入一些設定項可以進一步改善體驗:
quit-after-last-window-closed = true
quit-after-last-window-closed-delay = 5m
這個設定會讓 Ghostty 在最後一個視窗關閉五分鐘 後結束,從而在你一段時間未使用 Ghostty 時節省記憶體。
quit-after-last-window-closed = false
這個設定會讓 Ghostty 持續保持執行,使新視窗的 建立始終快速。
你可以讓 Ghostty 重新載入其設定(從指令稿或 CLI), 使用這條指令:
systemctl reload --user app-com.mitchellh.ghostty.service
背後它只是向主 Ghostty 程序發送一個 SIGUSR2,但
systemd 負責追蹤主 Ghostty 程序。用
ps 或類似工具把這段指令稿化並不太可靠。
新視窗可以用不帶參數的 ghostty CLI 建立。
不過,如果你正在使用 systemd 與 D-Bus 整合,
改用 ghostty +new-window 會快得多。
+new-window 指令會直接使用 D-Bus 建立新視窗。
如果 Ghostty 未在執行,D-Bus 啟用單元會啟動 Ghostty。
這比直接執行 ghostty 快得多,因為直接執行必須
載入設定、檢查環境、初始化 GTK 等
才能得出同樣的結論。
ghostty +new-window
即使 Ghostty 尚未執行,這依然會建立新視窗, 因為 D-Bus 啟用會導致 Ghostty 被啟動。
這條指令對 i3、Hyprland 或 River 等 視窗管理器特別有用。
以下是在 Hyprland 中把 super+return 綁定為
開啟新 Ghostty 視窗的一個示例。該設定
通常放在 ~/.config/hypr/hyprland.conf:
bind = SUPER, return, exec, ghostty +new-window
在帶有 systemd 與 D-Bus 的系統上,Ghostty 預設
透過 D-Bus 啟用來啟動。
應用啟動器並不直接執行 Ghostty,而是向 D-Bus
會話代理發送訊號,請求它開啟一個
Ghostty 視窗。D-Bus 會話代理知道
Ghostty 是否在執行,因為 Ghostty 會
註冊一個特定的匯流排名稱(com.mitchellh.ghostty)。
如果有程式註冊了這個匯流排名稱,就假定
是 Ghostty。
從這一點起,行為取決於 Ghostty 是否已在執行。
這一過程確保:只有當有作用中的視窗、或 Ghostty 被設定為持續執行(預設不是)時,GTK (或任何其他初始化)造成的啟動延遲才會 被承擔一次。
如果 Ghostty 已在執行,代理會 直接向 Ghostty 發送一個 D-Bus 訊號,請求 建立新視窗。Ghostty 監聽該訊號並 開啟一個新視窗。這非常快,非常省。
如果 Ghostty 未在執行,D-Bus 會話代理會
請求 systemd 以使用者服務的方式
啟動 Ghostty,然後在 Ghostty 啟動後
向它發送 D-Bus 訊號,請求
建立新視窗。
本「其他」部分收集較不關鍵 或不常使用的資訊。這些資訊可能仍然 極為有用(因此記錄在此),但不是 常常會用到的。
透過 systemd 執行時 Ghostty 發出的日誌可以使用
journalctl 檢視:
journalctl -a -f --user -u app-com.mitchellh.ghostty.service
以下指令會顯示 Ghostty 的狀態:
systemctl status --user app-com.mitchellh.ghostty.service
它應產生類似以下的輸出:
● app-com.mitchellh.ghostty.service - Ghostty
Loaded: loaded (/home/mitchellh/.local/share/systemd/user/app-com.mitchellh.ghostty.service; disabled; preset: enabled)
Active: active (running) since Fri 2025-07-11 14:05:42 PDT; 24h ago
Invocation: 42b48b0aa1bf4134a030e38acb04b8dd
Main PID: 2525 (ghostty)
Tasks: 0 (limit: 71639)
Memory: 81.4M (peak: 107.9M)
CPU: 98ms
CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/app-com.mitchellh.ghostty.service
‣ 2525 /home/mitchellh/.local/bin/ghostty --launched-from=systemd
Jul 11 14:05:42 beach ghostty[2525]: info(gtk): cgroup isolation enabled base=/user.slice/user-1000.slice/user@1000.service/app.slice/app-ghostty-transient-2525.scope
Jul 11 14:05:42 beach systemd[2268]: Started Ghostty.
Jul 11 14:05:42 beach ghostty[2525]: info(gtk): received new window action
Jul 11 14:05:42 beach ghostty[2525]: info(opengl): loaded OpenGL 4.6
Jul 11 14:05:42 beach ghostty[2525]: info(io_exec): found Ghostty resources dir: /home/mitchellh/.local/share/ghostty
Ghostty 的 systemd 使用者服務可以透過執行
以下指令停止:
systemctl stop --user app-com.mitchellh.ghostty.service
Caution
這會優雅地停止 Ghostty,但 Ghostty 會關閉全部 視窗並終止其中正在執行 的程序,_ 不請求確認 _。這 可能導致資料 或狀態 遺失。
正確安裝1時,Ghostty 會附帶 數個用於啟動 Ghostty 的設定檔。
如果以使用者身份安裝(例如在
$HOME/.local),會建立以下檔案:
$PREFIX/share/applications/com.mitchellh.ghostty.desktop
$PREFIX/share/dbus-1/services/com.mitchellh.ghostty.service
$PREFIX/share/systemd/user/app-com.mitchellh.ghostty.service
如果以系統套件安裝,會建立以下檔案:
$PREFIX/share/applications/com.mitchellh.ghostty.desktop
$PREFIX/share/dbus-1/services/com.mitchellh.ghostty.service
$PREFIX/lib/systemd/user/app-com.mitchellh.ghostty.service
Warning
如果這些檔案未安裝到正確的位置,或設定不正確,Ghostty 可能無法啟動。如果 它們已安裝到正確的位置但 Ghostty 依然 不啟動,請登出並重新登入。如果 仍然不行,接著嘗試重新啟動系統。這 很少是必要的,但依據系統設定 可能發生。
如果安裝的是 Ghostty 的開發建置(Debug
模式),本頁上的路徑需要稍微調整:
systemctl enable --user app-com.mitchellh.ghostty-debug.service
systemctl stop --user app-com.mitchellh.ghostty-debug.service
systemctl reload --user app-com.mitchellh.ghostty-debug.service
journalctl -a -f --user -u app-com.mitchellh.ghostty-debug.service
ghostty +new-window --class=com.mitchellh.ghostty-debug.service
這些是以使用者身份安裝時 控制 Ghostty 除錯版本啟動的檔案:
$PREFIX/share/applications/com.mitchellh.ghostty-debug.desktop
$PREFIX/share/dbus-1/services/com.mitchellh.ghostty-debug.service
$PREFIX/share/systemd/user/app-com.mitchellh.ghostty-debug.service
如果以系統套件安裝,這些檔案位於以下 位置:
$PREFIX/share/applications/com.mitchellh.ghostty-debug.desktop
$PREFIX/share/dbus-1/services/com.mitchellh.ghostty-debug.service
$PREFIX/lib/systemd/user/app-com.mitchellh.ghostty-debug.service