How To Install And Use bzip2 in Ubuntu

Table of Content
    Add a header to begin generating the table of contents
    Learn how to install and use bzip2 in Ubuntu for compressing and decompressing.
      Add a header to begin generating the table of contents

      bzip2 is a well-known command-line tool for compressing and decompressing different types of files. It employs Huffman coding and the Burrows-Wheeler block sorting text compression algorithm to compress the files.

      Moreover, bzip2 is useful for archiving and backups, providing high compression ratios for larger files. However, it might take more time to compress or decompress files compared to other tools. Bzip2 is compatible with numerous Unix-based systems, including Ubuntu.

      This tutorial will explain how to install and use bzip2 in Ubuntu.

      How To Install bzip2 in Ubuntu

      There are various methods to install bzip2 in Ubuntu. However, in this blog, we’ll talk about some of the most frequent ones.

      1. Using apt Command

      This is the most recommended and straightforward way to install bzip2 in Ubuntu. To do so, navigate to the terminal and execute the apt command to update and upgrade the system packages:

      $ sudo apt update && sudo apt upgrade

      Afterward, run the apt install command to install the bzip2 from Ubuntu’s official repository:

      $ sudo apt install bzip2
      Install bzip2 in Ubuntu using apt command

      Eventually, you’ve successfully installed the bzip2 in Ubuntu.

      2. Using Source Code

      This is the second method to install bzip2 by assembling it from the source. To do so, first, download the source code from the bzip2 Official Website or through the wget command:

      $ sudo wget https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz
      Download b2zip tar file using wget command in Ubuntu

      Once the download is complete, you’ll have a compressed archive created using tar (Tape Archive). Now, you’ve to extract this tarball file.

      $ sudo tar -xvf bzip2-1.0.8.tar.gz
      Extract Tarball File of bzip2

      Afterward, run the cd command to move into the unzipped directory. Then, use the make command to assemble the source code:

      $ cd bzip2-1.0.8
      $ sudo make
      Compile Source Code

      Now your system is ready to install the bzip2 in Ubuntu. Let’s execute the make command to set up the bzip2:

      $ sudo make install
      Execute Make Command to install bzip2

      Finally, you’ve successfully installed the bzip2 in Ubuntu by compiling it from source.

      How To Use bzip2 in Ubuntu

      bzip2 is a command-line tool used to compress and decompress files in Ubuntu. Let’s learn its usage through some examples.

      Compress File Using bzip2

      Execute the following bzip2 command to compress the simple.txt file:

      $ sudo bzip2 simple.txt
      Compress Single File

      This will replace the simple.txt file with the compressed file simple.txt.bz2

      Decompress File Using bzip2

      If you want to decompress the file and restore it to its original form. Then, run the bzip2 command with the -d flag:

      $ sudo bzip2 -d simple.txt.bz2
      Decompress Single File

      Hold Back the Original File using bzip2

      If you don’t want to replace the original file while compressing, execute the bzip2 command with the -k flag:

      $ sudo bzip2 -k simple.txt
      Hold back Original File

      Compress Multiple Files Using bzip2

      Moreover, bzip2 can also be used to compress numerous files. To do this, simply add the file names with spaces in the bzip2 command to compress them, as shown below:

      $ sudo bzip2 file1.txt file2.txt file3.txt
      Compress Multiple Files using bzip2 in Ubuntu

      Decompress Multiple Files Using bzip2

      Execute the bzip2 command with the -d flag to decompress multiple files:

      $ sudo bzip2 -d file1.txt.bz2 file2.txt.bz2 file3.txt.bz2
      Decompress Multiple Files using bzip2 in ubuntu

      This way, you’ve learned how to install and use bzip2 in Ubuntu successfully.

      Conclusion

      bzip2 is a powerful tool that manages large files and saves disk space. In this article, you’ve learned how to install and use bzip2 in Ubuntu through two methods: using the apt command and compiling from the source. Additionally, we discussed its basic usage, like compressing and decompressing single and multiple files.

      All in all, you can follow this blog to seamlessly integrate bzip2 into your workflow to compress or decompress files.

      Latest Post

      Contents
        Add a header to begin generating the table of contents
        Learn how to install and use bzip2 in Ubuntu for compressing and decompressing.
        Latest Post
        Do You Enjoy My Blog

        Supports from reader you like keeps this blog running. By a cup of coffee for me , its a affordable way to show your appreciation

        Previous Post
        ABOUT THE AUTHOR
        Samina Manzoor

        I'm a technical writer with a Bachelor's in Computer Science. Through my research and writing, I aim to provide readers with comprehensive, informative articles that can assist them make informed decisions about their technological needs.

        Scroll to Top