Packing an EPUB file is more specific than just creating a ZIP archive. Because EPUB is a standard, it has a strict internal structure and a specific "first-file" rule that must be followed for the file to be valid.
Here is how to pack your EPUB manually or using tools.
1. The "Magic" Rules for EPUB
To pass validation, your EPUB must meet these three conditions:
-
The
mimetypefile must be first: It must be the very first file in the ZIP archive. -
No compression on
mimetype: Themimetypefile must be stored (0% compression), while everything else can be compressed. -
No extra fields: The
mimetypefile cannot have any extra ZIP headers or "hidden" metadata.
2. Using Command Line
This is the most reliable way to ensure the mimetype is handled correctly. Open your terminal/command prompt inside your book's root folder.
On macOS / Linux
Run these two commands in order:
-
Pack the mimetype (uncompressed):
zip -0Xq mybook.epub mimetype
-
Pack everything else (compressed):
zip -9rXq mybook.epub * -x mimetype
(Note: -0 means no compression; -X excludes extra file attributes like .DS_Store.)