How to Calibre Server on Ubuntu 22.04

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Calibre is known for being a very efficient eBook manager and with important features to be ranked as one of the best. We can also deploy Calibre Server on Ubuntu 22.04 and thus have a more private management and accessible from anywhere.

One of the main advantages of deploying our eBook server with Calibre is that it will be accessible using the Internet. This will also allow you to share it with family and friends without problems, and finally, you can read your eBooks from the web.

So let’s get started.

Install Calible eBook Server on Ubuntu 22.04

First, connect to your SSH server and update the whole server:

sudo apt update
sudo apt upgrade

Then install some packages necessary for the installation:

sudo apt install libopengl0 libxkbcommon-x11-0 libegl1 libfontconfig libgl1-mesa-glx

Thanks to wget download the Calibre installation script.

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

Make it executable:

chmod +x ./linux-installer.sh

And finally run it.

sudo ./linux-installer.sh

This script will download and install the latest stable version of Calibre Server.

During the installation process, you will notice some warnings because the installer expects a graphical environment. Don’t worry, you can ignore these warnings.

Creating the library for Calibre Server

Now we have to set up a directory which is where the Calibre server will use as a library. So create the folder with whatever name you want and in whatever path. In this post, we will use the HOME folder.

mkdir library

Now download any eBook to test Calibre. Thanks to project Gutenberg, this is easy. For example:

wget https://www.gutenberg.org/ebooks/43782.kindle.noimages -O book.mobi

The format that Calibre handles best is kindle so I have chosen it, but with a mobi output format that is compatible and fully supported as well.

Now using the calibredb command you can add the downloaded book to the library.

calibredb add book.mobi --with-library library/
Added book ids: 1

Needless to say, you can add many using the * wildcard or via scripts.

Then, you can serve the library we have created.

calibre-server library

Sample Output:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-angelo'.
calibre server listening on 0.0.0.0.0:8080

Now it will be accessible from a web browser and from your server address on port 8080.

Setting up the Calibre eBooks server

Although at this point we could end the post, the truth is that there are a few details missing that will improve the user experience.

First, it is not very productive to have to start and stop the server in this way. The best thing to do is to make a new systemd service.

Stop running the server by pressing CTRL + C.

And create a new service file

sudo nano /etc/systemd/system/system/calibre-server.service

Now add the following content:

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

[Service]
Type=simple
User=angelo
Group=angelo
ExecStart=/opt/calibre/calibre-server /home/angelo/library --enable-local-write

[Install]
WantedBy=multi-user.target

Modify the User and Group values to your username and in ExecStart modify the user as well and make sure the path and library name are correct.

Save the changes and close the editor.

Refresh the Systemd services.

sudo systemctl daemon-reload

Now enable the service you have already created and initialize it.

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

Finally, check the status of the service

sudo systemctl status calibre-server
Calibre Server service status
Calibre Server service status

Optional: Configure Nginx as Reverse Proxy

Another aspect that we can improve is to use Nginx as a reverse proxy for Calibre to better configure access to the server.

So, install Nginx

sudo apt install nginx

And create the configuration file for Calibre

sudo nano /etc/nginx/conf.d/calibre.conf

Add this content

server {
  listen 80;
  listen [::]:80;
  server_name your-domain;

  location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
    proxy_set_header Connection $http_connection;
    proxy_set_header Upgrade $http_upgrade;
  }
}

From there, you will have to modify the server_name value to the value of your domain. Save the changes and close the editor.

Note: This is a pretty basic configuration of Nginx as a Reverse Proxy. I invite you to improve it and adapt it to your needs.

To apply the changes, just restart the service

sudo systemctl restart nginx

Finally, you can enable HTTPS on the server thanks to Certbot and Let’s Encrypt.

sudo apt install certbot python3-certbot-nginx

Now generate and install the certificates with the following command

sudo certbot --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email] -d [your-domain]

This should suffice.

Optional: Enable user authentication

To secure the server, you may want to enable user authentication.

First, stop the Calibre service

sudo systemctl stop calibre-server

Now enter the user management

sudo calibre-server --manage-users

You will get a menu where you have to select the Add a new user option.

Then, enter the username and password of your choice.

When the console exits, it is time to edit the service file we have created. In short, the line to edit is the ExecStart line.

From this

ExecStart=/opt/calibre/calibre-server /home/angelo/library --enable-local-write

To this

ExecStart=/opt/opt/calibre/calibre-server "/home/angelo/calibre-library" --userdb "/home/angelo/.config/calibre/server-users.sqlite" --enable-local-write --enable-auth

Save the changes, refresh the services and start the Calibre service.

sudo systemctl daemon-reload
sudo systemctl start calibre-server

Done.

Log in to Calibre eBooks server

Now open your web browser and visit your domain. After logging in, you will see this screen.

Calibre Ebook Server running
Calibre Ebook Server running

And you will be able to choose the created library

Using Calibre server
Using Calibre server

Enjoy it.

Conclusion

Calibre is a marvel available to everyone and especially to those who enjoy and consume a lot of eBooks. Now as a server, you can use it from anywhere and even share it.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook