How to install lz4c in ubuntu

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: To install lz4c on Ubuntu, you can use the APT package manager. Open your terminal and run the command `sudo apt update && sudo apt install lz4` to install the lz4 compression utility, which includes the `lz4c` executable.

Key Facts

Overview

LZ4 is a lossless data compression algorithm and associated compression and decompression tool. It is designed to be very fast, both in terms of compression and decompression speed, while offering a reasonable compression ratio. The `lz4c` command is the command-line interface for the LZ4 compression utility. Installing it on Ubuntu is straightforward and typically involves using the system's package manager.

Why Use LZ4/lz4c?

In the realm of data compression, there's often a trade-off between compression ratio (how small the data becomes) and speed (how quickly compression and decompression occur). LZ4 prioritizes speed. This makes it an excellent choice for scenarios where data needs to be compressed and decompressed rapidly, such as:

While it might not achieve the same compression ratios as algorithms like gzip or bzip2, its speed advantage can be significant in performance-critical applications.

Installation Steps on Ubuntu

Ubuntu, like most Debian-based distributions, uses the Advanced Package Tool (APT) for managing software packages. Installing `lz4c` (which is part of the `lz4` package) is a simple process:

  1. Open Terminal: You can open the terminal by pressing Ctrl+Alt+T or by searching for "Terminal" in the application menu.
  2. Update Package List: Before installing any new software, it's good practice to update your local package index. This ensures that you are aware of the latest available versions of packages and their dependencies. Run the following command:
sudo apt update

This command downloads the latest package information from all configured sources. You may be prompted to enter your user password.

  1. Install LZ4: Now, install the `lz4` package, which contains the `lz4c` executable. Run the following command:
sudo apt install lz4

APT will then calculate the dependencies, show you which packages will be installed, and ask for your confirmation. Press Y and then Enter to proceed.

Verification

Once the installation is complete, you can verify that `lz4c` is installed and accessible by checking its version or running a simple compression/decompression test.

Check Version

lz4c --version

This command should output the installed version of LZ4.

Basic Compression Test

Create a sample text file:

echo "This is a test file for lz4c compression." > test.txt

Compress the file using `lz4c`:

lz4c test.txt test.txt.lz4

You should now have a compressed file named `test.txt.lz4`. You can check its size relative to the original `test.txt`.

Decompress the file:

lz4c -d test.txt.lz4 test.txt.decompressed

This will create `test.txt.decompressed`. You can compare `test.txt` and `test.txt.decompressed` to ensure the compression and decompression process worked correctly.

Common Usage of lz4c

The `lz4c` command offers several options for compression and decompression. Here are a few common use cases:

lz4c input_file output_file.lz4
lz4c -d compressed_file.lz4 output_file
  • Piping data (compressing standard input to standard output):
  • cat large_file | lz4c > large_file.lz4
    • Piping data (decompressing standard input to standard output):
    cat large_file.lz4 | lz4c -d > large_file
  • Using block mode for better compression on multiple files (though `lz4` command is often preferred for this):
  • lz4c -B 1024KB input_dir output_dir.lz4

    Note: For more advanced batch processing or managing multiple files, the `lz4` command itself (without the `c` suffix) might offer more features or be the intended tool. However, `lz4c` is the standard executable for direct file compression/decompression and piping.

    Troubleshooting

    If you encounter issues during installation:

    • "Unable to locate package lz4": This usually means your package list is not up-to-date. Run `sudo apt update` again and try the install command. If it still fails, ensure your Ubuntu repositories are correctly configured.
    • Permissions errors: Ensure you are using `sudo` for commands that require root privileges.

    In summary, installing and using `lz4c` on Ubuntu is a simple process that enhances your system's capabilities for high-speed data compression.

    Sources

    1. Ubuntu Packages Search - lz4fair-use
    2. LZ4 - Extremely Fast CompressionCC0-1.0
    3. LZ4 - WikipediaCC-BY-SA-4.0

    Missing an answer?

    Suggest a question and we'll generate an answer for it.