Reading is a joy, and with modern technology you can access an almost infinite library of literature from the device in your pocket. But managing your ebook and comic collection can be hard, and transferring and syncing content between devices is tricky if you don't want to tie yourself to a proprietary service.

Kavita is an open source ebook server which runs on Raspberry Pi and lets you organize, sync, and read on any device.

Why Host an Ebook Server on Raspberry Pi?

Amazon logo on side of building.

Most of the knowledge, hopes, dreams, and creative output of mankind over the past 6,000 years is written down in books. Sure, websites are great, but you don't have to travel too far from this page before you hit on dead links and missing resources. As a reader, you know that it's a pleasure to own your own library, where you can dip into great works of literature, classic novels, or personal development resources.

If you use Amazon's Kindle platform, you don't own the books you buy—you are instead purchasing a license to access the content in your account. You might think that this is a small and academic difference, but it's not. Amazon can and does delete purchased content from your Kindle and from your account. Particularly notable for its attendant irony was a 2009 incident in which Amazon remote wiped copies of George Orwell's 1984 and Animal Farm from devices.

While Amazon pinky-promised that such things would never happen again, there's nothing other than goodwill and a non-binding statement preventing them from nuking your entire library. Amazon isn't alone in this, and most ebook retailers grant themselves similar licenses to the content you think you own.

Amazon, iTunes, Barnes and Noble will probably be around for decades to come, but if they eventually shutter their services, what happens to your library? Given Google's track record with closing down its own services (as listed on Killed by Google), you'd need to be exceptionally brave to consider building a lasting literary collection using the Google Play Books service.

Restricting access to books for which you own a license is possible because of Digital Rights Management, and we've already published guides on how to remove DRM from your ebooks. You can also buy literature without any DRM whatsoever.

The problem comes when you realize that you like to read on multiple devices and synchronize your progress between them; you also want to be able to easily browse your library, make lists, and add new books whenever it suits you. Kavita is a fast, feature rich, open source reading server which can do all that and more.

Install Kavita on Raspberry Pi

Before you start, follow our essential guide to setting up your Raspberry Pi as a web server.

You can install Kavita on older Raspberry Pi models, as well as 64-bit OSes. If you intend to use Kavita on a 64-bit OS, use wget to download the 64-bit archive:

        wget https://github.com/Kareadita/Kavita/releases/download/v0.7.1.4/kavita-linux-arm64.tar.gz
    

Otherwise, download the standard ARM version:

        wget https://github.com/Kareadita/Kavita/releases/download/v0.7.1.4/kavita-linux-arm.tar.gz
    

Extract the archive with:

        tar -xzf kavita-linux-arm64.tar.gz
    

Use the cd command to navigate to the Kavita directory, and make the binary executable:

        cd ~/Kavita
sudo chmod +x Kavita

If you want to have Kavita start as a service at boot, use the nano text editor to create a new file:

        sudo nano /etc/systemd/system/kavita.service
    

Add the following lines:

        [Unit]
Description=Kavita Server
After=network.target

[Service]
User=kavita
Group=kavita
Type=simple
WorkingDirectory=/home/pi/Kavita
ExecStart=/home/pi/Kavita/Kavita
TimeoutStopSec=20
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target

Save and exit nano with Ctrl + O then Ctrl + X.

Installation With Docker

Alternatively, Docker and Docker Compose offer a simple way to download and install Kavita. First, use the following command to create directories for Kavita and your libraries, then move into your new Kavita directory:

        mkdir kavita kavita/books kavita/comics kavita/data && cd kavita
    

Create a new Docker Compose file with:

        nano docker-compose.yml
    

Add the following content to the file:

        version: '3.2'
services:
    kavita:
        image: kizaing/kavita:latest
        container_name: kavita
        volumes:
            - ./comics:/comics
            - ./books:/books
            - ./data:/kavita/config
        environment:
            - TZ=Europe/London
        ports:
            - "5000:5000"
        restart: unless-stopped

Copy your books and comics into the relevant directory, then download Kavita images and bring the containers up with:

        docker-compose up -d
    

Use Kavita to Manage Your Digital Library

register initial kavita user

In your browser, navigate to your.pi.local.ip.address:5000 to see the front end of your new Kavita library.

Create an admin account by entering a username and password. If you skip the email address, you'll see a warning: "This field is required". Feel free to ignore this as Kavita doesn't actually require an email address. However, if you need to recover your password, an email address will come in handy.

The interface you see will be bare, and sadly empty, apart from a tip stating, "There are no libraries set up yet. Configure some in Server settings."

Click on the link, then enter a name for your first library, and select the type from the dropdown list. Click Next, then Browse for media folders.

If you used the examples in our docker-compose, you should be able to find the relevant folders under /books, and /comics. Select /books, then press the green Share button.

kavita library view

Clicking Next will allow you to set an image for your library. You can enter a URL, drag and drop a file, or upload an image using your system's file manager.

On the next screen, you can set some basic management options for Kavita using toggles. These relate to search, folder monitoring, and the way series are treated. When you're happy with the options, click Save, then press the Scan library button.

Kavita requires books to be in their own individual directories. If your books are loose EPUB or PDF files, you can use the following terminal command to create subdirectories and move your books into them:

        find /path/to/your/books/* -prune -type f -exec sh -c 'mkdir -p "${0%.*}" && mv "$0" "${0%.*}"' {} \;
    

If your books are part of a series, consult the folder requirements documentation (on the Kavita wiki) to learn how Kavita scans books.

Access Kavita Outside Your Local Network

kavita reading view

Of course, you'll want to read books from your Kavita server when you're on the bus or in cafes, and grant library access to friends and family.

Head over to your domain registrar's Advanced DNS settings page. Delete all records and create a new A record. Set the host to "@", value to your public IP address, and the TTL as low as possible.

On your Raspberry Pi, use the cd command to navigate to /etc/apache2/sites-available.

        cd  /etc/apache2/sites-available
    

Create a new conf file with:

        sudo nano kavita.conf
    

In it, paste the following:

        <VirtualHost *:80>
ServerName your.domain.tld
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http:/127.0.0.1:5000/
ProxyPreserveHost On
</VirtualHost>

Save and exit nano with Ctrl +O then Ctrl + X, then enable the new conf and restart Apache:

        sudo a2ensite kavita.conf
sudo service apache2 restart

Enable Transport Layer Security with:

        sudo certbot
    

Enter the information requested, then restart Apache again:

        sudo service apache2 restart
    

You and your friends can now access your Kavita ebook server from anywhere in the world!

Read your own eBooks with Kavita

If you want to read ebooks using Kavita, you'll need to use a web browser, as there are currently no native clients available. This isn't a huge deal, as Kavita's built-in reader is quite competent.

Click on a book thumbnail and the reader will open along with a configuration sidebar. From here, you can fine-tune details, including font, layout, and color schemes, before proceeding with your reading.

If you're on mobile, log in to your Kavita instance using the credentials you set up earlier, then select Add to Home screen from the menu. This will create a new shortcut on your home screen, from which Kavita will open in full-screen mode.

Reading Isn't Always Good for You

While reading is a fabulous way to spend your time, reading too much can give you eyestrain, and potentially annoy a partner if you're enjoying late-night literature while they're asleep.

If you want all the benefits that reading affords without threatening your eyesight or relationship, consider self-hosting an audiobook server instead.