How to Create An Online Dictionary with Dico in Linux

Spread the love

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.

Content

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

  1. 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

  1. Download the GNU Dico source archive from the developer’s website:
wget https://ftp.gnu.org/gnu/dico/dico-2.11.tar.xz

  1. Extract the program archive in your current working directory:
tar xvJf ./dico-2.11.tar.xz

  1. Go inside the program’s directory.
cd ./dico-2.11
  1. Run Dico’s initial configuration script:
./configure

  1. Start the program’s compilation process:
make

  1. 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.

  1. Download GCIDE from the maintainer’s website:
wget ftp://ftp.gnu.org/gnu/gcide/gcide-0.53.tar.xz

  1. Extract the archive using tar:
tar xvJf ./gcide-0.53.tar.xz

  1. 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.

  1. Go to your “/usr/local/etc” directory:
cd /usr/local/etc/

  1. Create the GNU Dico configuration file:
sudo touch ./dicod.conf
  1. Open your new configuration file using your favorite text editor:
sudo nano ./dicod.conf
  1. 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;
  1. Save your configuration file by pressing Ctrl + O, then Ctrl + X.

  1. Test your GNU Dico installation:
sudo dicod --foreground
  1. Run an instance of the Dico console program by running dico on a separate terminal.

  1. Type .open localhost to connect to the local Dico instance.

  1. 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.

  1. Create a systemd service file:
touch personal-dicod.service
  1. Open your new service file using your favorite text editor:
nano personal-dicod.service

  1. 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

  1. Copy your service file to the systemd services directory:
sudo cp ./personal-dicod.service /etc/systemd/system/

  1. Create the directory where dicod will store its pidfile:
sudo mkdir /run/dicod
sudo chown -R dicod:dicod /run/dicod

  1. Reload systemd to apply your new configuration:
sudo systemctl daemon-reload
  1. 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.

  1. To install the package, press Alt + X, then type “package-install.”

  1. Type “dictionary” in the command buffer prompt.

  1. After that, press Alt + X, then type “customize-variable.”

  1. Type “dictionary-server” in the new buffer prompt.

  1. Select the text box beside the “Dictionary Server” label and type localhost.

  1. Click “Apply and Save” to commit your new setting.

  1. 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.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


Ramces Red
Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

Comments are closed