Build Calibre Ebook Server

Introduction

calibre is a free and open source ebook manager that’s well known for its cross-platform desktop application. You can use calibre to manage your ebook library on a single device, but the application also includes a powerful server component. Setting up an ebook server allows your to:

  • Access your books from anywhere in the world
  • Easily transfer your books to mobile devices
  • Share books with your friends and family

Prerequisites

  • Step 1 - Downloading and Installing the calibre Content Server

First, install some necessary dependencies

$ sudo apt update && sudo apt install -y libfontconfig libgl1-mesa-glx libegl1 libopengl0

Now download and install the calibre server.

$ wget https://download.calibre-ebook.com/linux-installer.sh

Now execute the script to install calibre

$ sudo sh linux-installer.sh
  • Step 2 - Creating a Library and Adding Your First Book

Create a directory that calibre can use as your ebook library

$ mkdir /mnt/inner-disk/calibre-library

Add the book to your new library using the calibredb command

$ calibredb add *.mobi --with-library /mnt/inner-disk/calibre-library
  • Step 3 - Running the calibre Content Server and Viewing Your Library

port 8080, which is the default port for calibre.

Run the following command to start the calibre content server:

$ calibre-server /mnt/inner-disk/calibre-library

visit your_server_ip:8080 and you will see the default calibre screen.

  • Step 4 - Creating a Service for the calibre Content Server

create a file called calibre-server.service in the directory /etc/systemd/system/

$ sudo vim /etc/systemd/system/calibre-server.service

Add the following configureations, which will start the calibre Content server on boot.

[Unit]
Description=calibre content server
After=network.target

[Service]
Type=simple
User=sammy
Group=sammy
ExecStart=/opt/calibre/calibre-server /mnt/inner-disk/calibre-library --enable-local-write

[Install]
WantedBy=multi-user.target

Enable the service and start it:

$ sudo systemctl enable calibre-server
$ sudo systemctl start calibre-server

Reboot your server:

$ sudo reboot
  • Step 5 - Adding User Authentication to the calibre Content Server

First, stop calibre. This will allow us to manipulate calibre’s database directly

$ sudo systemctl stop calibre-server

Start calibre’s user management script

$ calibre-server --manage-users

Reopen calibre-server.service

$ sudo vim /etc/systemd/system/calibre-server.service

To enable authentication, add the --enable-auth flag to the end of the line starting ExecStart.

ExecStart=/opt/calibre/calibre-server /mnt/inner-disk/calibre-library --enable-local-write --enable-auth

Refresh the service daemon to rescan the services files

$ sudo systemctl daemon-reload
$ sudo systemctl start calibre-server
  • Step 6 - Automatically Adding Books to Your calibre Library

It can be useful to set up a cron job that watches a specific directory and adds any books it finds to your calibre library. This way, you can download or upload books to this folder and they’ll automatically becomes available via the calibre web interface.

Open your crontab

$ crontab -e

Add the following content

*/5 * * * * calibredb add /mnt/inner-disk/books-to-add-calibre -r --with-library http://localhost:8080#calibre-library && rm -r /mnt/ inner-disk/books-to-add-calibre

Reference materials

[1] How to Create a calibre Ebook Server on Ubuntu 20.04