Convert a text file to EPUB in Ubuntu

In this article, we would cover how to convert a text file to EPUB in Ubuntu. EPUB is basically an e-book file format. It is generally used to read books on smartphones, tablets etc. Since we can modify text according to the screen size through an application on such devices. Therefore, generally we prefer EPUBs over PDFs.

Although there are many packages which would let us convert a text file (.txt) to EPUB file format. But, for this article – we will stick with following command-line utility –


If we have Calibre package then, we can access the command-line utility. So, we need to first install the package if its not there.

Note: Following operations would require you to have superuser privileges. In case you don’t have one then we advise you to contact your System Administrator for assistance.

Just update the Ubuntu’s standard repository and use following code to install Calibre –

sudo apt update
sudo apt install calibre

Now, we can access ebook-convert command-line utility.

Convert a text file to EPUB in Ubuntu

Use following syntax for converting a text file to EPUB –

ebook-convert <input_file.txt> <output_file.epub> [options]

For instance, if we have a text file – FirstBook.txt and we want to convert the same to FirstBook.epub then, use the following –

ebook-convert FirstBook.txt FirstBook.epub

After it gets the processing done, we would get FirstBook.epub in the current directory. Open it with the supported application to view the contents. Calibre itself will provide an e-book viewer.

To adjust for line height, use the following option –

ebook-convert FirstBook.txt FirstBook.epub --line-height <pts>

where, <pts> is some numeric value.

Lastly, we can either set the EPUB version as 2 or 3 depending on our requirements. Use following code to convert the text file to a specific EPUB version file format –

ebook-convert FirstBook.txt FirstBook.epub --epub-version <version_number>

For EPUB version 2, use <version_number> as 2. Similarly, <version_number> for EPUB version 3.

In conclusion, we have covered how to convert a text file to EPUB in Ubuntu here.