The Quick-N-Dirty Guide to Inputting Japanese in Linux, FreeBSD and NetBSD

The aim of this QND guide is to get you up and running quickly and being able to input Japanese in Linux, FreeBSD and NetBSD. There will be far more how than why here.

1.) Do you have the Necessary Tools?

You will need a few items for this to work. They are canna, kinput2 and a terminal capable of displaying Japanese. I use rxvt, there is another one called mlterm. If your distribution has these packages available, that makes it easier. FreeBSD, NetBSD, Gentoo Linux and Fedora, nee RedHat, among others all have these available. Most other distributions do have rxvt and mlterm. (If you are using ArchLinux, use rxvt_ja from unofficial).

If you are unsure how to find these programs in your distribution, take a quick look at our software guide for information about getting and installing the items.

If you are running Slackware, Arch, Yoper, Crux or several others, you might find our vanilla kinput-canna tarball useful. Download it here take a quick look at our guide on installing from source then read on to step two, where we give a bit more information.

To see if you do have these programs at a command prompt type

which kinput2
which cannaserver
which rxvt
which mlterm

2.) Installing the Necessary Tools

If these packages were included with your distribution, then hopefully you’ve installed them. If you have to use our vanilla tarball, then do the following to install canna and kinput2.

tar -jxvf vanillajpn.tar.bz2
tar -zxvf Canna*
tar -zxvf kinput
cd Canna36p1
make Makefile
make canna
make install

Next, kinput2.
Do a cd back to the directory in which you untarred it and then

cd kinput2-v3.1-beta3
make Makefile
make depend
make install

In most cases, you will want cannaserver to start upon bootup. This varies with each distribution, so hopefully you know how to do it with yours. If not, check out our QND guide about running a program upon boot and see if your distribution is mentioned there.

3.) Configuring the Necessary Tools

I am assuming that you want your menus and such to be in English. Create a shell script. I usually put it in /usr/local/bin, but you can put it anywhere in your $PATH, including your ~/bin directory. For Linux it might work if you just put

XMODIFIERS="@im=kinput2"  LC_CTYPE=ja_JP ${1+"$@"} &

If your browser broke that, it should be two lines, the first one being the #!/bin/bash and everything else on the second line. For FreeBSD 5.x and NetBSD

XMODIFIERS='@im=kinput2' LANG=ja_JP.eucJP ${1+"$@"} &

The ja_JP.eucJP might, in different distributions, have to be EUCJP, EUC-JP or other variants. Usually you can determine which it should be by doing

locale -a | grep ja_JP

For example in FreeBSD I get


Therefore, I use eucJP rather than EUCJP.
Add the following to your .xinitrc (although in RedHat use .Xclients or .Xclients-default).

kinput2 -canna &

4.) Test the Necessary Tools

Fire up X. Open up an rxvt or mlterm terminal. Try calling a program with the langx script, for example

langx vi

Now, hit shift+space. You should see a hiragana a. (¤¢)¡£ Type in some romaji and you will see the proper hiragana appear. Then hit the space bar and assuming you have cannaserver running, you should see a choice of kanji that can be selected with the arrow keys.

5.) Some caveats

A few difficulties that I’ve had are outlined below.

Gentoo. Make sure that you have the cjk and nls USE variables defined in /etc/make.conf when installing various packages, otherwise you will find that things like mutt and w3m won’t work with Japanese.

Slackware. Prior to Slackware 9.1 the langx script had to be modified.

XMODIFIERS="@im=kinput2 LC_ALL=ja_JP ${1+"$@"} &

Also, if you didn’t install the glibc-i18n libraries during installation, you will have to grab the installation cd and install them. (They’re in the l directory. Note that is a lower case L, not the numeral “one”).

Free and NetBSD. In both of these, I never did get vi working correctly. I found that I had to use vim. (I didn’t find it necessary to use the Japanese one though, just took the one from /usr/ports/editors). Also, in NetBSD, one has to edit /usr/pkg/lib/X11/app-defaults/Rxvt. You will see several lines marked !Rxvt.multichar_encoding

Remove the ! from the line that has eucj at the end. Also, put a ! at the beginning of the top line, which ends with noenc.

Also, in NetBSD, you may get an error message when you start kinput2 that app-defaults can’t be loaded and you should modify your XFILESEARCHPATH. You can add it to your shell’s rc file. In Bourne style shells, such as sh, bash, ksh and zsh one would add

XFILESEARCHPATH=/usr/pkg/lib/X11/app-defaults/Kinput2; export

Doing a symbolic link also works.

cd /usr/X11R6/lib/X11/app-defaults
ln -s /usr/pkg/lib/X11/app-defaults/Kinput2 

In FreeBSD, there is a /usr/ports/japanese version of rxvt and w3m. Aside from those two, I didn’t find it necessary to use the Japanese version of any other programs

The rxvt terminal If installing rxvt from source (or using the package from various distros) you have to do the following when building the package.

./configure --enable-kanji --enable-xim

Congratulations, you’re done. Hopefully, you can now input Japanese in your *nix system.

References My page on Japanese input.
I have a far more detailed page on this, with links to other people’s pages as well.