Install Brotli Compression on Ubuntu 20.04 | Easy Guide
This tutorial provides a comprehensive guide on how to Install Brotli Compression on Ubuntu 20.04. Brotli, an open-source, lossless compression algorithm developed by Google in 2015, offers superior compression ratios and speeds compared to older algorithms like Gzip. Its efficiency makes it a valuable asset for optimizing web performance and reducing bandwidth consumption.
Brotli’s architecture is based on a modern iteration of the LZ77 algorithm, Huffman coding, and 2nd-order context modeling.
A key advantage of Brotli lies in its utilization of a pre-built dictionary within users’ browsers. This dictionary contains approximately 100,000 commonly used phrases and word fragments found on the web. By leveraging this dictionary, Brotli can significantly reduce the size of compressed files. This reduction in file size translates to faster loading times for websites and applications, enhancing the user experience. Install Brotli Compression on Ubuntu 20.04 to take advantage of these benefits.
The following steps, originally presented on the Orcacore website, detail the process of installing Brotli Compression on Ubuntu 20.04.
Before you begin, ensure you are logged in to your Ubuntu 20.04 server as a non-root user with sudo
privileges. If you haven’t already configured this, refer to a guide like the "Initial Server Setup with Ubuntu 20.04" for instructions.
This guide focuses on installing Brotli from the source code. Follow the steps below to complete the installation.
Install Brotli Compression Ubuntu 20.04 From Source
First, update your local package index to ensure you have the latest package information:
sudo apt update
Install Required Packages
Next, install the necessary packages and dependencies required for compiling and installing Brotli from source:
sudo apt install -y wget gcc make bc sed autoconf automake libtool git tree
Clone Brotli Repo From GitHub
Clone the Brotli repository from GitHub to your Ubuntu 20.04 server. This will download the source code required for building Brotli.
sudo git clone https://github.com/google/brotli.git
Navigate to the newly created brotli
directory:
cd brotli
Create a Manual Page for Brotli
Create a manual page for the Brotli command to provide documentation and help information.
sudo cp ~/brotli/docs/brotli.1 /usr/share/man/man1 && sudo gzip /usr/share/man/man1/brotli.1
Generate Autotools Configure File
Generate the Autotools configure file. This script will analyze your system and prepare the build environment.
./bootstrap
This command makes the standard C program build steps (configure
, make
, and make install
) available.
Build and Install Brotli Compression Ubuntu 20.04
Now, build and install Brotli on your Ubuntu 20.04 system using the following commands:
# ./configure --prefix=/usr
# --bindir=/usr/bin
# --sbindir=/usr/sbin
# --libexecdir=/usr/lib64/brotli
# --libdir=/usr/lib64/brotli
# --datarootdir=/usr/share
# --mandir=/usr/share/man/man1
# --docdir=/usr/share/doc
# make
# sudo make install
After the installation is complete, verify your Brotli installation by checking its version:
brotli --version
You can also access help information about the brotli
command using:
brotli -h

Conclusion
Data compression is a critical aspect of modern web development and usage. The increasing complexity and size of web files necessitate efficient compression techniques.
Brotli compression builds upon the foundations of GZIP but incorporates performance-enhancing features.
By following the steps outlined in this guide, you have successfully learned to Install Brotli Compression on Ubuntu 20.04.
Alternative Installation Methods
While the source installation method detailed above is effective, alternative approaches can simplify the process. Here are two alternative methods for installing Brotli on Ubuntu 20.04:
1. Using apt
Package Manager (If Available)
The easiest method is to check if Brotli is available as a package in the default Ubuntu repositories or through a PPA (Personal Package Archive). While it might not always be the latest version, it’s often sufficient for many use cases and avoids the complexities of compiling from source.
First, search for the Brotli package:
apt search brotli
If a package like brotli
or libbrotli-dev
is listed, you can install it directly:
sudo apt install brotli libbrotli-dev
Explanation:
apt search brotli
: This command searches the configured package repositories for packages with "brotli" in their name or description.sudo apt install brotli libbrotli-dev
: This command installs the Brotli command-line tool (brotli
) and the Brotli development library (libbrotli-dev
). The development library is useful if you want to integrate Brotli compression into your own software.
This method is significantly simpler and faster than compiling from source. However, the version available through apt
might not be the absolute latest.
2. Using a Pre-built Binary (if available)
Sometimes, instead of compiling from source, a pre-built binary package is available from the Brotli project or a third-party. These are often distributed as .deb
packages for Debian-based systems like Ubuntu.
- Check for Pre-built Binaries: Visit the Brotli GitHub repository or search online for pre-built
.deb
packages for your Ubuntu version. Be careful to only download from trusted sources. - Download the Package: Download the
.deb
package to your server. - Install the Package: Use
dpkg
to install the package:
sudo dpkg -i <package_name>.deb
- Fix Dependencies (if necessary): If there are dependency issues, run:
sudo apt-get install -f
Explanation:
sudo dpkg -i <package_name>.deb
: This command installs the downloaded.deb
package using thedpkg
package manager. Replace<package_name>.deb
with the actual filename of the package.sudo apt-get install -f
: This command attempts to fix any broken dependencies that might have occurred during the installation process.
This method offers a balance between simplicity and control. You avoid compiling from source, but you can potentially obtain a more recent version than what’s available in the default repositories. However, it requires finding and trusting a source for the pre-built binary.
Choosing the right installation method depends on your specific needs and priorities. If you need the absolute latest version and are comfortable with compiling, the source installation is the way to go. If simplicity is paramount and an older version is acceptable, using apt
is the best choice. Pre-built binaries offer a compromise, but require careful consideration of the source’s trustworthiness.
Data compression is a necessary component of developing and using the modern web. File sizes can skyrocket due to the rich and complex file types you’ll use to piece together a website. All of them need some form of compression. Install Brotli Compression on Ubuntu 20.04 can significantly reduce the size of compressed files.
Brotli compression bases its technology on the same foundation as GZIP but includes some performance-enhancing benefits.
Hope you enjoy it. You may also interested in these articles:
- Install PHP 8.2 on Ubuntu 20.04
- Install Python 3.11 on Ubuntu 20.04
- Set up SmartGit on Ubuntu 20.04
- Install and Configure XWiki on Ubuntu 20.04
- How to secure Nginx with Let’s Encrypt on Ubuntu 20.04
- Installing CouchDB on Ubuntu 20.04
- Install Slack on Ubuntu 20.04
- Install and Secure Odoo14 on Ubuntu 20.04
FAQs
How do I compress a file using Brotli?
You can use the command below:brotli input.txt
How do I decompress a Brotli file?
You can use the command below:brotli -d input.txt.br
Can Brotli be used for non-web applications?
Yes! Brotli can compress log files, data archives, and other text-based files efficiently.