Installing a calibre server on a Raspberry Pi 4 (Ubuntu Server)

The scope of this little project is simple: run a calibre ebook server off one of my Raspberry Pi 4 units. This particular Pi is running Ubuntu Server 20.04 LTS, so if yours is running something else, adjust the commands appropriately and as needed. I prefer the headless ease of use with Ubuntu Server, but whatever distro you choose ought to be fine. I just wanted to save resources on my Pi, since running an X server still costs horsepower, and my Pi has other tasks it needs to do.

I decided to write all of this down for two reasons: 1. So that I wouldn’t forget when I inevitably have to do it all again, and 2. So that someone else out there (you reading this) could have an easier time of it than I did. This took hours of googling, compiling miscellaneous instructions into something relevant for my system, and getting countless errors back in the terminal. Granted, the latter was mostly due to typos and fat-fingering on my part.

Running calibre via the command line is much less intuitive than using the GUI method, so if you have access to a desktop environment on your Pi, then you’ll have an easier time of organizing, adding, and changing library locations. Like I said, I opted to go headless, so I’m stuck with using calibre’s CLI tool, calibredb.

I spliced together instructions from this tutorial, which walks you through some different steps versus what I will. However, the gist is the same and it offers some good structure, so I won’t fix what ain’t broke. However, one bone that I have to pick with this tutorial is the use of rysnc to copy your ebooks to the local calibre directory. When I did this, it nuked all of my ebooks. Poof, gone. They weren’t in the source directory on my NAS anymore, nor were they in the destination directory. They’re lost somewhere between my DiskStation and my Pi. Alas.

Because of that, I will be using the good ol’ cp command. It’s not as elegant, but it’ll work for now. I suggest using a test PDF first to make sure everything goes smoothly, then add your library later (which I’ll discuss calibredb syntax further on). Obviously, I take no responsibility if you break your machine. I’m not a Linux expert by any means, though I know enough to be dangerous. I will be using the commands that I typed to accomplish my end goal.

Installing calibre

I won’t walk you through installing Ubuntu Server because it’s pretty easy. For sake of my sanity, I did change the default username from ‘ubuntu’ to ‘admin,’ though I left the home directory name the same because I like how it looks in the command line. Weird, I know. If you want Pi-specific instructions on getting Server up and running, change the username, and all that, I can probably write a quick how-to for you. It seriously takes all of half an hour at most.

Moving on, here’s the meat and potatoes of the whole affair.

Install calibre.

  • sudo apt install calibre

Once it’s done installing, you’ll need to set up a directory for the calibre library to call home.

  • sudo mkdir ~/CalibreLibrary

Next, you need to get your ebooks copied over to the new calibre library. I keep mine on a NAS and share them via SMB. I will show you how I mount my NAS, though yours will be a different IP and directory.

  • sudo mount -t cifs -o cred=~/.smbcredentials //192.168.1.2/library /mnt/XANA_NAS/library

Copy the ebooks to your CalibreLibrary folder.

  • sudo cp -r /mnt/XANA_NAS/library ~/CalibreLibrary

Done? Cool, let’s turn calibredb into a systemd service.

Creating a systemd service for calibreserver

The reason we’re doing this is so that you don’t have to trigger calibredb every time you want it to run. That takes up a terminal window and just doesn’t work for me. The solution is to create a systemd service for calibreserver to run in the background and it’s really simple.

Start by creating a new config file for the service.

  • sudoedit /etc/systemd/system/calibreserver.service

Enter the following (making adjustments to fit your system as needed):

  • [Unit]
    Description=Run a calibre server on the local network
    After=network.target

    [Service]
    Type=oneshot
    ExecStart=/usr/bin/calibre-server /home/ubuntu/CalibreLibrary/

    [Install]
    WantedBy=multi-user.target

Exit nano (CTRL+X to exit, Y to save, Enter to finish) and start up the service.

  • sudo systemctl enable — now calibreserver.service

Creating the calibre library via the command line

Alright, so we’ve created the calibre library and made a calibreserver.service to have it run in the background. Cool stuff. Here’s the part I really struggled with.

You’ll find the documentation for calibredb to be kinda okay. It’s functional, but the former technical writer in me wants more, especially specific examples for the commands and options. This was a huge source of frustration for me, trying to get everything up and running.

If you don’t know, you can head to the IP address your Raspberry Pi with the port 8080 to see what your library looks like right now. There oughtn’t be anything just yet, but that’s next. It’s time to spin up calibredb and get your library sorted.

There are a lot of options for calibredb and I won’t go into all of them here, partially because I’m too lazy and partially because I don’t know what all of them do yet. Yes, humility is one of my strong suits.

Note: The em dashes ( — ) you see here are supposed to be two separate dashes in the terminal. Medium just autocorrects two en dashes to an em dash. Which is nice most of the time, except here. There should be a space between the command and the global option (where you see the em dash).

The command you need to know is this: calibredb add — with-library /path/to/library /path/to/books

Okay, here’s where I’m a bit iffy on things. Earlier, I had you copy over your library (or test PDF) to ~/CalibreLibrary. The way I think that it works is that’s where the books live for calibre to serve up when you access the server later on. I’m still testing honestly, but I think you could use the following syntax:

  • calibredb add — with-library /home/ubuntu/CalibreLibrary /home/ubuntu/CalibreLibrary

Again, I’m not 100% sure on that. If you play around with it and I’m wrong, let me know. When I get some new ebooks or have the motivation to get another test PDF, I’ll give it a shot. For now, I told calibredb’s add command to pull the books from my NAS. I’m working on automating this process. If you have tips, pray tell.

There are options with each command. The one I’ve used thus far is the author command, or the -a argument. This allows you to tell calibredb what the author is. For example, I bought a bundle of IT books from Humble, all of whom were from the same publisher. So when I added them to calibre, I said:

  • calibredb add -a “No Starch Press” — with-library /home/ubuntu/CalibreLibrary /mnt/XANA_NAS/library/NoStarchPress

Final thoughts

Alright, so that’s that. I have a functional calibre server running on a headless Ubuntu system. Using Moon+ Reader on Android, I can access my library easily, as long as I’m on my home network — outside the network is the next thing I want to tackle.

I prefer EPUB format, but I also have a Kindle. Unfortunately, I don’t know if it’s possible to use calibre’s conversion function via calibredb. At least at time of writing, I didn’t see it in the documentation. I also haven’t figured out to how remove remnants of old books or my test PDF from the library. Some data wasn’t corrupted my first time using rsync to copy everything over from my NAS, and calibre has held onto that old metadata for dear life. Again, this is a limitation of calibredb so if you have access to the GUI, you may not have this problem.

Have fun reading your stuff.

Phones Editor for Tom’s Guide. Opinions expressed here are my own.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store