The mdBook is a command line tool used to create modern, interactive, and online books from Markdown files. It is particularly popular within the Rust programming community because it was originally designed to generate documentation for Rust projects, but it has since become useful for many other purposes. This tutorial shows how to install mdBook on Ubuntu 24.04.
Install mdBook
Check the latest mdBook version in the GitHub repository and store it in a variable:
MDBOOK_VERSION=$(curl -s "https://api.github.com/repos/rust-lang/mdBook/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
Download the mdBook archive:
wget -qO mdbook.tar.gz https://github.com/rust-lang/mdBook/releases/latest/download/mdbook-v$MDBOOK_VERSION-x86_64-unknown-linux-gnu.tar.gz
Extract executable to /usr/local/bin
directory:
sudo tar xf mdbook.tar.gz -C /usr/local/bin mdbook
We can check mdBook version with command:
mdbook --version
Remove the unneeded archive:
rm -rf mdbook.tar.gz
Testing mdBook
The mdBook provides the init
command that creates a project with a few essential files:
mdbook init mybook --force
The command creates a new project in a directory named mybook
. The --force
option skips the prompts to create a .gitignore
and for the title for the book, which can be added later.
The build
command is used to render the book:
mdbook build mybook
It will parse Markdown files and creates HTML files.
The serve
command is used to preview a book by serving it over HTTP:
mdbook serve mybook -n 0.0.0.0
Open a web browser and go to http://<IP_ADDRESS>:3000
, where <IP_ADDRESS>
is the IP address of the system. A newly created book will appear.
Uninstall mdBook
To uninstall mdBook, delete the corresponding file:
sudo rm -rf /usr/local/bin/mdbook
Leave a Comment
Cancel reply