Never Ending Security

It starts all here

How To use Calibre on Linux


Although Calibre is probably better known for its desktop client, it can also act as a powerful server, allowing you to access your ebooks from anywhere in the world (or share your collection with friends). Keeping your ebooks on a server is great, as you aren’t reliant on having the same reading device with you whenever you want to read. And if you go traveling, you don’t need to worry about taking your ebook collection with you!

home-featureThe server includes a simple and elegant browser front-end that allows you to search for and download books from your library. It also has a mobile-friendly site built in, making it easy to download books straight to an e-reader – even to ones with only the most basic web functionality.

For example, Calibre’s browser works with the Kindle Touch, which can download books directly even though the device only has an e-ink display and an experimental browser.

In this tutorial we’ll look at how to install, set up, and use Calibre on a Ubuntu 14.04 server. We’ll also take a look at how to use thecalibredb command to create, customize, and maintain your ebook database right from the server.

For this tutorial we’ll cover:

  • Installing Calibre
  • Creating an ebook library, or importing an existing one
  • Making Calibre server a background service
  • Automatically adding new books to the library

By the end of this tutorial, you’ll have a small initial library to which you can easily add new books!

Installing Calibre

Calibre is available from the APT software repositories, but as advised by its creators it is far better to install from the binaries provided on their website. Calibre is updated very frequently and the version in the repos tends to lag behind.

Luckily, the creators of Calibre have made this very simple to do. Just run the following Python command on your server. Before running the command, please double-check the official Calibre site in case the command has been changed.

Install Calibre:

sudo -v && wget -nv -O- | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(; main()"

Installing Dependencies

The Calibre command line tool calibredb is used for various operations on your Calibre library, such as adding or importing books, and fetching metadata and covers for books.

We’ll take a look at how to use some of these commands later, but for now we’ll just install two dependencies. The first is ImageMagick, without which calibredb won’t run; and the second is xvfbwhich we’ll use to run calibredb in a virtual X display server – in order to sidestep issues caused by running Calibre in a non-display environment.

To install these just run the following commands.

Update your package lists:

sudo apt-get update

Install xvfb:

sudo apt-get install xvfb

Install ImageMagick:

sudo apt-get install ImageMagick

Creating the Library

Now we’re almost ready to start running the server. We need to get some books to serve, however.

You may well have your own ebook library already, so we’ll look at two ways of doing this.

  1. Add ebook files directly; we’ll grab a couple from Project Gutenberg
  2. Import an existing Calibre library; useful if you’re already running the desktop version of Calibre

Getting Books

First let’s make a directory for our Calibre library. This example creates the directory in your user’s home directory, although you could place it anywhere on the server. Run the following commands:

mkdir ~/calibre-library
mkdir ~/calibre-library/toadd

We’ve created two directories: the first, ~/calibre-library is the one that Calibre will organize automatically, while we’ll add books manually to the toadd sub-directory. Later, we’ll take a look at how to automate this process too.

How we’ll grab some books from Project Gutenberg. For this tutorial we’ll download Pride and Prejudiceby Jane Austen and A Christmas Carol by Charles Dickens.

Change to the toadd directory to get started.

cd ~/calibre-library/toadd

Download the two ebooks:

wget -O
wget -O

Calibre relies somewhat on file extensions to correctly add books, so the -O flag in the wget command specifies a more friendly filename. If you downloaded a different format from Gutenberg (such as .epub) then you need to change the file extension accordingly.

Adding the Books to Calibre’s Database

Now we need to add these books to the Calibre database using the calibredb command through thexvfb virtual display we installed earlier. To do this, run:

xvfb-run calibredb add ~/calibre-library/toadd/* --library-path ~/calibre-library

The asterisk means that Calibre will add all books found in the toadd directory to the library, in the calibre-library directory. You might see an error about not finding a cover (we chose to download the .mobi files without images), but you should also see confirmation that the books were added to the Calibre database.

Sample output:

Failed to read MOBI cover
Backing up metadata
Added book ids: 1, 2
Notifying calibre of the change

That’s all we need to start seeing the first results. Let’s test out the server. Run:

calibre-server --with-library ~/calibre-library

The command won’t produce any output, but will just appear to hang in your terminal. This is fine for now; we’ll look at daemonizing it properly later. Now open a web browser and navigate to:

  • http://your_server_ip:8080

Replace your_server_ip with your Droplet’s IP address. You should see the main page of your library, looking similar to the screenshot below.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s