Dico is a modern implementation of the traditional DICT protocol. It aims to create a fully modular dictionary server software that you can host almost anywhere. This tutorial shows how you can install and use Dico as your local “online” dictionary server in Linux.
Alternative: you can also install the SDCV dictionary app in the Linux terminal.
What Is an Online Dictionary and Why Use One?
Dictionary (DICT) servers are Internet programs that load and serve word definitions from an internal file. Unlike web dictionaries, DICT servers can be incredibly lightweight and flexible to changes, making it attractive for users that want to maintain their own dictionary at home.
Aside from that, modern DICT servers are also fully compatible with GNU Emacs, so you can create a Dico server, link it with GNU Emacs and load word definitions from inside the editor.
Lastly, DICT servers are also simple and easy to implement. Hosting one can be a good and fun starting point if you are a beginner at deploying Internet services.
Good to know: once you have your feet wet deploying server software, a good next step would be hosting your own Email server.
Installing GNU Dico
- Run the following command to obtain GNU Dico’s dependencies.
sudo apt install wget gcc make m4 m4-doc python3 libltdl-dev libdico2 zlib1g-dev
- Download the GNU Dico source archive from the developer’s website:
wget https://ftp.gnu.org/gnu/dico/dico-2.11.tar.xz
- Extract the program archive in your current working directory:
tar xvJf ./dico-2.11.tar.xz
- Go inside the program’s directory.
cd ./dico-2.11
- Run Dico’s initial configuration script:
./configure
- Start the program’s compilation process:
make
- Install the program in your system’s “/usr/local/bin” directory:
sudo make install
Obtaining an Online Dictionary Database
Once you have installed the GNU Dico binary, download a dictionary database. It contains all the definitions that the program will serve once it is up and running.
One of the easiest ways to get a dictionary database is through the GNU Collaborative International Dictionary of English (GCIDE). It’s a free and open source collection of English words and definitions that spans back to 1913.
- Download GCIDE from the maintainer’s website:
wget ftp://ftp.gnu.org/gnu/gcide/gcide-0.53.tar.xz
- Extract the archive using tar:
tar xvJf ./gcide-0.53.tar.xz
- Copy the archive to your machine’s “/usr/local/share/” directory:
sudo cp -rv ./gcide-0.53 /usr/local/share/
Configuring and Running GNU Dico
At this point, your system has a basic GNU Dico installation. For example, you can run dico in your terminal, and it will give you a basic prompt.
However, you still need to configure some of its settings to make it work properly for your machine.
- Go to your “/usr/local/etc” directory:
cd /usr/local/etc/
- Create the GNU Dico configuration file:
sudo touch ./dicod.conf
- Open your new configuration file using your favorite text editor:
sudo nano ./dicod.conf
- Add the following lines of code, a version of the default conf file that I have modified to work with GCIDE.
capability (mime,xversion); timing yes; pidfile /var/run/dicod/dicod.pid; module-load-path ("/usr/local/lib/dico"); load-module gcide; database { name "gcide"; handler "gcide dbdir=/usr/local/share/gcide-0.53 suppress-pr"; languages-from "en"; languages-to "en"; } user dicod; max-children 18; inactivity-timeout 5; server-info <<EOT This is a Dico server. EOT;
- Save your configuration file by pressing Ctrl + O, then Ctrl + X.
- Test your GNU Dico installation:
sudo dicod --foreground
- Run an instance of the Dico console program by running
dico
on a separate terminal.
- Type
.open localhost
to connect to the local Dico instance.
- Test your new Dico server by sending any English word to the console prompt.
Configure GNU Dico to Autostart During Bootup
You can create a systemd service for GNU Dico, allowing you to easily manage your online dictionary and run it without a dedicated command line.
- Create a systemd service file:
touch personal-dicod.service
- Open your new service file using your favorite text editor:
nano personal-dicod.service
- Add the following lines of code inside your service file:
[Unit] Description=A basic GNU Dico Daemon Service [Service] ExecStart=/usr/local/bin/dicod -f --stderr [Install] WantedBy=multi-user.target
- Copy your service file to the systemd services directory:
sudo cp ./personal-dicod.service /etc/systemd/system/
- Create the directory where dicod will store its pidfile:
sudo mkdir /run/dicod sudo chown -R dicod:dicod /run/dicod
- Reload systemd to apply your new configuration:
sudo systemctl daemon-reload
- Start your GNU Dico service by running the following commands:
sudo systemctl enable personal-dicod.service sudo systemctl start personal-dicod.service
Tip: if you intend on running GNU Dico on a public network, secure your Linux server from malicious actors.
Linking GNU Dico to GNU Emacs
Aside from using the GNU Dico console, you can also integrate your new dictionary server to external applications. For example, easily link your Dico server with GNU Emacs by using the “dictionary.el” package.
- To install the package, press Alt + X, then type “package-install.”
- Type “dictionary” in the command buffer prompt.
- After that, press Alt + X, then type “customize-variable.”
- Type “dictionary-server” in the new buffer prompt.
- Select the text box beside the “Dictionary Server” label and type
localhost
.
- Click “Apply and Save” to commit your new setting.
- You can search your dictionary server by pressing Alt + X, then typing “dictionary-search” in the command buffer prompt.
FYI: Emacs is more than just a dictionary browser. Learn how you can also use it to create beautiful LaTeX documents without knowing any TeX code.
Frequently Asked Questions
Dicod immediately terminates whenever I run it.
While this can be due to a number of issues, the most common cause for this is a misconfigured PID file. You can fix this by making sure that the dicod user and group exists in your system: sudo groupadd dicod && sudo useradd -s /usr/sbin/nologin -d /var/lib/dicod -g dicod dicod
.
Also double check your “dicod.conf” file for any additional errors by running: dicod -t
.
Is it possible to use a different online dictionary with GNU Dico?
Yes. However, you also need to make sure that Dico is loading the new dictionary’s module and database block in its “dicod.conf” file. For example, to use the dict.org database, you need to download a copy of its database files and load its module in your Dico configuration file.
The dictionary.el package does not exist in my Emacs repository.
You can add the dictionary.el package by including the MELPA repositories in your init.el file. For example, the following line adds the “MELPA Stable” branch to your Emacs installation: (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
.
Image credit: Unsplash. All alterations and screenshots by Ramces Red.
Our latest tutorials delivered straight to your inbox