> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-12-localization-and-input-methods/di-12.4-jie-ibus-shu-ru-fa-kuang-jia.md).

# 12.4 IBus Input Method Framework

IBus stands for "Intelligent Input Bus", an input method framework widely used in Linux and UNIX-like systems.

## Installing the IBus Input Method Framework

* Install using pkg:

```sh
# pkg install ibus zh-ibus-libpinyin
```

Where `zh-ibus-libpinyin` is the intelligent Pinyin input method.

* Or install using Ports:

```sh
# cd /usr/ports/textproc/ibus/ && make install clean
# cd /usr/ports/chinese/ibus-libpinyin/ && make install clean
```

Optional input methods include:

| Port                         | Description                                             |
| ---------------------------- | ------------------------------------------------------- |
| `chinese/ibus-cangjie`       | Cangjie input method                                    |
| `chinese/ibus-chewing`       | New Chewing input method                                |
| `chinese/ibus-rime`          | Rime input method engine                                |
| `chinese/ibus-table-chinese` | Includes Wubi, Cangjie, and various other input methods |

## Configuring Environment Variables

To set variables for Simplified Chinese UTF-8 encoding, edit the **\~/.login\_conf** file and add the following content:

```ini
me:\
        :lang=zh_CN.UTF-8:\
        :setenv=LC_ALL=zh_CN.UTF-8,LC_COLLATE=zh_CN.UTF-8,LC_CTYPE=zh_CN.UTF-8,LC_MESSAGES=zh_CN.UTF-8,LC_MONETARY=zh_CN.UTF-8,LC_NUMERIC=zh_CN.UTF-8,LC_TIME=zh_CN.UTF-8,XIM=ibus,GTK_IM_MODULE=ibus,QT_IM_MODULE=ibus,XMODIFIERS="@im=ibus",XIM_PROGRAM="ibus-daemon",XIM_ARGS="--daemonize --xim":\
        :charset=UTF-8:
```

The meanings of the input method-related environment variables are as follows:

| Variable                       | Description                                                                                                                             |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| `XIM=ibus`                     | Specifies the X Input Method (XIM) framework as IBus                                                                                    |
| `GTK_IM_MODULE=ibus`           | Specifies that GTK applications use the IBus input method module                                                                        |
| `QT_IM_MODULE=ibus`            | Specifies that Qt applications use the IBus input method module                                                                         |
| `XMODIFIERS="@im=ibus"`        | Specifies that X applications connect to IBus via the XIM protocol                                                                      |
| `XIM_PROGRAM="ibus-daemon"`    | Specifies the path to the XIM daemon                                                                                                    |
| `XIM_ARGS="--daemonize --xim"` | Specifies the startup arguments for ibus-daemon; `--daemonize` means running as a background daemon, `--xim` means enabling XIM support |

After editing, execute the following command to update the login capability database:

```sh
$ cap_mkdb ~/.login_conf
```

### Wayland

Under Wayland, the environment variable configuration for IBus differs from X11. GNOME has integrated IBus since version 3.6, and under GNOME Wayland, there is no need to manually set `GTK_IM_MODULE` and `QT_IM_MODULE`. For other desktop environments, the configuration strategy for `GTK_IM_MODULE` and `QT_IM_MODULE` is similar to Fcitx 5 (see Section 12.3 Wayland section). `XIM_PROGRAM` and `XIM_ARGS` are only used in X11/XWayland environments and are not needed in pure Wayland sessions.

## Configuring IBus

After completing the environment variable configuration, set up IBus using the following method.

IBus setup tool:

```sh
$ ibus-setup
```

![IBus](/files/laLB9ND9dDQ4n5iwMOyl)

## UTF-8 Encoding

IBus requires UTF-8 encoding, but does not restrict the specific locale value (such as `C.UTF-8` or `zh_CN.UTF-8`).

![IBus](/files/xikOoiFQVaqMCVEZ1qKf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-12-localization-and-input-methods/di-12.4-jie-ibus-shu-ru-fa-kuang-jia.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
