How To Install Calibre Server & Calibre Web On Ubuntu 22.04

Calibre is a free, open source and easy to use e-book manager. Calibre supports organizing existing e-books into virtual libraries, displaying, editing, creating and converting e-books, as well as syncing e-books with a variety of e-readers. Editing books is supported for EPUB and AZW3 formats.

First, we install Calibre and then Calibre Web.

1. Update and upgrade Ubuntu

$ sudo apt update -y && sudo apt upgrade -y

2. Reboot your server (if necessary):

$ sudo reboot now

3. Configure firewall ports (if necessary – ports 8081 and 8083 need to be allowed):

$ sudo ufw allow http
$ sudo ufw allow https
$ sudo ufw allow 8081
$ sudo ufw allow 8083

4. Create a new Calibre user

Create a new user for Calibre and give it superuser privileges:

$ sudo adduser calibre
$ sudo usermod -aG sudo calibre

Log out and log back in with the new user you just added.

5. Install dependencies

$ sudo pip3 install pyqt5
$ sudo apt-get install libgl1-mesa-glx libxdamage1 libegl1 libxkbcommon0 libopengl0 libxkbcommon-x11-0 libfontconfig

6. Download and install Calibre-server

$ sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin

You may notice some warnings about failed desktop integration, but these are safe to ignore, since you are installing Calibre on a remote server.

7. Create Calibre library directories

Log out and log back in with the new user you just added. Then make a directory for the Calibre library and uploads.

$ sudo mkdir calibre-library
$ sudo mkdir calibre-upload

Change ownership permissions of the directories:

$ sudo chown -R calibre:calibre calibre-library
$ sudo chown -R calibre:calibre calibre-upload
$ sudo chown -R calibre:calibre .config
$ sudo chmod ugo+rw calibre-upload

8. Add a sample e-book

Download a sample e-book to load into the upload directory:

$ cd calibre-upload
$ sudo wget http://www.gutenberg.org/ebooks/219.epub.noimages -O heart.epub

Then add the e-book to the library:

$ sudo calibredb add ~/calibre-upload/* --library-path ~/calibre-library

9. Test the server

To test the server, launch with the following command (you can substitute the port 8180 with something else):

$ sudo calibre-server --port=8081 --enable-local-write ~/calibre-library

Then open your web browser and go to:

http://yourwebsite.com:8081 or if using a local LAN, http://192.168.0.XX:8081 (replace ‘XX' with the coorect IP Address)

When you are satisfied everything works, go back to the command line and Ctrl+C to exit.

10. Add a log file

Add a log file and change its ownership permissions:

$ cd ~
$ sudo touch ~/calibre.log
$ sudo chown -R calibre:calibre ~/calibre.log

11. Add / Manage Calibre Users

$ sudo calibre-server --userdb /home/calibre/.config/calibre/server-users.sqlite --manage-users

Then follow the prompts. Repeat to add, edit or remove users.

12. Starting Calibre server at boot

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

Add the code below changing User, Group, port and the location to the calibre-library directory (in this case /home/calibre/calibre-library):

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

[Service]
Type=simple
User=calibre
Group=calibre

ExecStart=/usr/bin/calibre-server\
--max-opds-items=30\
--max-opds-ungrouped-items=100\
--port 8081 \
--log="/home/calibre/calibre.log"\
--enable-auth \
--userdb="/home/calibre/.config/calibre/server-users.sqlite"\
"/home/calibre/calibre-library"

[Install]
WantedBy=multi-user.target

Ctrl+X to Save and Exit.

Then start the server with:

$ sudo systemctl start calibre-server.service

Check the status with:

$ sudo systemctl status calibre-server.service

Then to start at boot:

$ sudo systemctl enable calibre-server.service

More

If you have make any changes to calibre-server.service, reload:

$ sudo systemctl daemon-reload

To stop calibre-server:

$ sudo systemctl stop calibre-server.service

You can uninstall Calibre by running:

$ sudo calibre-uninstall

13. Installing Calibre-Web

Calibre-Web is a web app providing a clean interface for browsing, reading and downloading eBooks using an existing Calibre database.

Make sure you are logged in as the user calibre. Make sure that we have a python version 3+ installed. Check your python version:

$ python3 --version

example output:

Python 3.10.12

Now simply install Calibre Web with the code below:

$ pip3 install calibreweb

Start Calibre-Web:

$ nohup cps

You can now close the terminal and Calibre Web will still run at http://yourwebsite.com:8083 or http://192.168.0.XX:8083 (replace ‘XX' with the coorect IP Address).

14. Starting Calibre-Web on boot

Start Calibre-Web as service under Linux with systemd:
https://github.com/janeczku/calibre-web/wiki/Setup-Service-on-Linux

$ sudo nano /etc/systemd/system/cps.service

Add this and replace the elements in {} like User, ExecStart and WorkingDirectory with your username, file and foldernames:

[Unit]
Description=Calibre-Web

[Service]
Type=simple
User=calibre
ExecStart={path to python} {/PATH/TO/cps.py including cps.py}
WorkingDirectory={/PATH/OF/CPS.PY without cps.py}

[Install]
WantedBy=multi-user.target

Example:

[Unit]
Description=Calibre-Web

[Service]
Type=simple
User=calibre
ExecStart=/usr/bin/python3 /home/calibre/calibre-web/cps.py
WorkingDirectory=/home/calibre/calibre-web

[Install]
WantedBy=multi-user.target

Ctrl+X to Save and Exit.

Enable the service:

$ sudo systemctl enable cps.service

15. Optional features for installation with pip

Optional features of Calibre-Web can be installed with pip by executing pip install calibreweb[extraname]. The “[” and “]” are part of the command.

See the list of optional features here: https://github.com/janeczku/calibre-web/wiki/Dependencies-in-Calibre-Web-Linux-and-Windows

Example:

$ sudo pip3 install calibreweb[gmail]

When you go to http://yourwebsite.com:8083 or if using a local LAN, http://192.168.0.XX:8083 (replace ‘XX' with the coorect IP Address), you will have to set the location of the Calibre database.

This is where the metadata.db is. In this case, /home/calibre/calibre-library. Click submit. The default admin login is:

Username: admin
Password: admin123

MORE

1. You can add the path to your SSL certifile (for https) in Calibre Web at Admin settings > Basic Configuration > Server Configuration.

Moving calibre installation to a new server

http://www.mobileread.mobi/forums/showthread.php?t=145490
Install Calibre on your new server.
Copy all contents of the calibre-library folder into the new calibre-library folder of the new server.

https://manual.calibre-ebook.com/faq.html#id50
The most important thing to backup is the calibre library folder, that contains all your books and metadata. This is the folder you chose for your calibre library when you ran calibre for the first time. You can get the path to the library folder by clicking the calibre icon on the main toolbar. You must backup this complete folder with all its files and sub-folders.

You can switch calibre to using a backed up library folder by simply clicking the calibre icon on the toolbar and choosing your backup library folder. A backed up library folder backs up your custom columns and saved searches as well as all your books and metadata.

If you want to backup the calibre configuration/plugins, you have to backup the config directory. You can find this config directory via Preferences → Miscellaneous. Note that restoring configuration directories is not officially supported, but should work in most cases. Just copy the contents of the backup directory into the current configuration directory to restore.

REFERENCES

https://calibre-ebook.com/download_linux
https://manual.calibre-ebook.com/server.html
https://www.mobileread.com/forums/showthread.php?t=288408
https://github.com/janeczku/calibre-web
https://github.com/janeczku/calibre-web/wiki/Dependencies-in-Calibre-Web-Linux-and-Windows
https://www.howtoforge.com/how-to-install-calibre-ebook-server-on-ubuntu-22-04/
https://stackoverflow.com/questions/66607640/unable-to-import-qtwebenginepage-from-pyqt5-on-aws-linux
https://stackoverflow.com/questions/71929876/importerror-cannot-import-name-qcolorconstants-from-pyqt5-qtgui

For info on Calibre performance, see:
https://www.mobileread.com/forums/showthread.php?t=208618

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.