GhosttyをWSL2にインストールして使う

はじめに

Ghosttyは、最近注目されているターミナルエミュレーターで、パフォーマンスとモダンなUI/UXを重視して設計されている。

流行りに乗って、WSL2上でGhosttyをインストールして使う方法を紹介する。 この機会に開発環境を快適にしてみる…!

Windows版は現時点では公式には「Coming Soon」または試験的な扱いだが、WSL2のWSLg(Windows Subsystem for Linux GUI)機能を使えば利用できる。

WSLgはWindows 11の最新ビルドやWindows 10の特定バージョン以降で利用可能で、WSL2内でGUIアプリを実行すると自動的にWindowsデスクトップ上にウィンドウが表示される機能である。

環境

Windows 11 Pro
WSL2 (Ubuntu 24.04 LTS)

インストール手順

Ghosttyはコミュニティによってメンテナンスされているインストールスクリプトやパッケージが利用可能である。

コミュニティ版パッケージを利用する

公式ドキュメントでも紹介されている、Ubuntu向けのインストールスクリプトを利用するのが手軽である。
Ghostty Ubuntu Install

以下のコマンドを実行する。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/mkasberg/ghostty-ubuntu/HEAD/install.sh)"
ログ
Installing/Updating Ghostty...
Downloading ghostty_1.2.3-0.ppa1_amd64_24.04.deb...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 15.8M  100 15.8M    0     0  70.0M      0 --:--:-- --:--:-- --:--:-- 70.0M
Installing ghostty_1.2.3-0.ppa1_amd64_24.04.deb...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'ghostty' instead of './ghostty_1.2.3-0.ppa1_amd64_24.04.deb'
ghostty is already the newest version (1.2.3-0~ppa1).
The following packages were automatically installed and are no longer required:
  crack-common gyp libcares2 libgl1-amber-dri libglapi-mesa libjs-async libjs-events libjs-inherits
  libjs-is-typedarray libjs-prettify libjs-regenerate libjs-source-map libjs-sprintf-js
  libjs-typedarray-to-buffer libllvm17t64 liblttng-ust-common1t64 liblttng-ust-ctl5t64 liblttng-ust1t64
  libnotify-bin libqt5x11extras5 libre2-10 libssl-dev libuv1-dev libxcb-damage0 mesa-utils-bin node-abbrev
  node-ampproject-remapping node-ansi-regex node-ansi-styles node-aproba node-are-we-there-yet node-arrify
  node-async node-async-each node-auto-bind node-babel-plugin-add-module-exports node-babel7-runtime
  node-balanced-match node-base64-js node-binary-extensions node-brace-expansion node-busboy
  node-camelcase node-caniuse-lite node-chownr node-chrome-trace-event node-ci-info node-cjs-module-lexer
  node-cli-boxes node-cli-cursor node-clone node-collection-visit node-color-convert node-color-name
  node-colors node-commander node-commondir node-concat-stream node-console-control-strings
  node-convert-source-map node-core-js node-core-js-pure node-core-util-is node-data-uri-to-buffer
  node-decompress-response node-deep-is node-defaults node-define-property node-delegates node-depd
  node-diff node-electron-to-chromium node-encoding node-end-of-stream node-err-code node-error-ex
  node-es-module-lexer node-escape-string-regexp node-eslint-utils node-eslint-visitor-keys node-esquery
  node-estraverse node-esutils node-events node-fancy-log node-fast-deep-equal node-fast-levenshtein
  node-fetch node-find-up node-flatted node-foreground-child node-fs-readdir-recursive
  node-fs-write-stream-atomic node-fs.realpath node-function-bind node-get-caller-file node-get-stream
  node-get-value node-glob node-globals node-got node-graceful-fs node-growl node-has-flag
  node-has-unicode node-has-value node-has-values node-hosted-git-info node-iconv-lite node-ieee754
  node-iferr node-imurmurhash node-indent-string node-inflight node-inherits node-ini node-interpret
  node-ip node-ip-regex node-is-arrayish node-is-binary-path node-is-buffer node-is-descriptor
  node-is-extglob node-is-path-cwd node-is-plain-obj node-is-plain-object node-is-stream
  node-is-typedarray node-is-windows node-isarray node-isexe node-isobject node-js-tokens node-json-buffer
  node-json-parse-better-errors node-json-schema node-json-schema-traverse node-json-stable-stringify
  node-jsonify node-jsonparse node-kind-of node-levn node-loader-runner node-locate-path
  node-lodash-packages node-lowercase-keys node-lru-cache node-map-visit node-memfs node-merge-stream
  node-mimic-response node-minimatch node-minimist node-minipass node-mute-stream node-n3 node-negotiator
  node-npm-run-path node-object-inspect node-object-visit node-once node-optimist node-optionator
  node-osenv node-p-cancelable node-p-limit node-p-locate node-p-map node-pascalcase node-path-dirname
  node-path-exists node-path-is-absolute node-path-is-inside node-path-type node-pify node-pkg-dir
  node-postcss-value-parser node-prelude-ls node-process-nextick-args node-promise-inflight
  node-promise-retry node-promzard node-prr node-pump node-punycode node-quick-lru node-randombytes
  node-read node-readable-stream node-rechoir node-regenerator-runtime node-regenerator-transform
  node-regexpp node-regjsgen node-repeat-string node-require-directory node-require-from-string
  node-resolve node-resolve-cwd node-resolve-from node-restore-cursor node-resumer node-retry
  node-run-queue node-safe-buffer node-serialize-javascript node-set-blocking node-set-immediate-shim
  node-shebang-command node-shebang-regex node-shell-quote node-signal-exit node-slash node-slice-ansi
  node-source-list-map node-source-map node-spdx-correct node-spdx-exceptions node-spdx-expression-parse
  node-spdx-license-ids node-sprintf-js node-ssri node-stack-utils node-string-decoder node-strip-bom
  node-supports-color node-tapable node-terser node-text-table node-through node-time-stamp
  node-to-fast-properties node-tslib node-type-check node-typedarray node-typedarray-to-buffer node-undici
  node-unicode-canonical-property-names-ecmascript node-unicode-match-property-value-ecmascript
  node-unicode-property-aliases-ecmascript node-unset-value node-uri-js node-util-deprecate node-uuid
  node-v8flags node-validate-npm-package-license node-wcwidth.js node-webpack-sources node-wordwrap
  node-wrappy node-write-file-atomic node-xtend node-y18n node-yallist node-yaml nodejs-doc xbitmaps
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.

このスクリプトは、必要な依存関係のチェックや.debパッケージのダウンロード・インストールを行ってくれる。

Snapを利用する場合

Snapを利用している場合は、以下のコマンドでもインストール可能である。

sudo snap install ghostty --classic

起動と確認

インストールが完了したら、WSL2のターミナルから以下のコマンドでGhosttyを起動できる。

ghostty

WSLgが正常に機能していれば、黒い画面のターミナルウィンドウがWindowsのデスクトップ上に現れる。

↓ 起動した画面の例 Ghostty on WSL2

もし起動しない場合は、WSLgの環境(ドライバ更新など)や、依存しているライブラリ(libgtk-4など)が不足していないか確認するとよいかも。

設定

設定ファイルは ~/.config/ghostty/config に配置する。 ディレクトリがない場合は作成する。

mkdir -p ~/.config/ghostty
touch ~/.config/ghostty/config

設定はシンプルな key = value 形式で記述する。例としていくつか設定してみる。

# フォントサイズ
font-size = 14

# テーマ
theme = catppuccin-mocha

# カーソル
cursor-style = block
cursor-style-blink = false

# ウィンドウの装飾(WSLgだと反映されない場合もありますが)
window-decoration = true

保存後、Ghosttyを再起動するか、設定によっては即座に反映される。 利用可能なテーマや設定項目は公式ドキュメントを参照されたい。

トラブルシューティング

libEGL warning: DRI3 error が表示される場合

起動時に以下のようなエラーが表示され、正常に動作しないことがある。

libEGL warning: DRI3 error: Could not get DRI3 device
libEGL warning: Ensure your X server supports DRI3 to get accelerated rendering

これはWSL2のGPUハードウェアアクセラレーション(WSLg)が正常に機能していない、あるいはLinux側のドライバと連携できていない場合に発生する。
別の記事にも記載しているが、今回もzshを使っていた時に発生した。
bashに切り替えたら問題なかったが、下記の2を設定することでzshでも問題なく動作したので記載しておく。

1. WSLとドライバの更新

WindowsのPowerShellで wsl --update を実行し、WSLを最新にする。また、GPUドライバも最新のものに更新する。

2. ソフトウェアレンダリングを使用する

GPUアクセラレーションを無効化してCPUで描画させることで回避できる。

export LIBGL_ALWAYS_SOFTWARE=1
ghostty

毎回上のコマンド打つのは面倒なので、以下を ~/.bashrc あるいは ~/.zshrc(zshを使用している場合)などに追記する。

export LIBGL_ALWAYS_SOFTWARE=1

参考

おわりに

使ってみたがWSL上だとちょっともっさりしている感じがある。
Windows版が正式にリリースされたら、そちらを試してみたいな…。

Hugo で構築されています。
テーマ StackJimmy によって設計されています。