UNRAR is a tool used to extract files from RAR archives, a common file format for compressing and archiving data. It is essential for users who frequently download or receive files in the RAR format and need a reliable way to extract their contents. On Ubuntu, there are two main versions of UNRAR available: the proprietary unrar package and the open-source unrar-free. While both allow users to extract RAR files, the proprietary version typically offers broader support for newer RAR formats and features, whereas unrar-free provides a fully open-source alternative, albeit with some limitations in compatibility and features.
On Ubuntu 24.04, 22.04, or 20.04, you can install either version of UNRAR depending on your needs. The proprietary unrar package offers full compatibility with RAR files, including the ability to handle more complex archives, while unrar-free provides a more basic, open-source solution. This guide will walk you through the installation of both unrar and unrar-free using the command-line terminal, helping you choose the version that best suits your requirements.
Update Ubuntu Before Installing UNRAR
To begin, update your Ubuntu system. This step ensures your system has the latest features and security patches, making it ready for new installations. Execute the following command in the terminal:
sudo apt update && sudo apt upgrade
Install UNRAR via APT Install Command
After updating your system, you can install UNRAR. This utility is essential for extracting RAR files. Use this command to install UNRAR from RARLAB, which is a proprietary version offering full compatibility with various RAR formats:
sudo apt install unrar
Alternative: Installing UNRAR-Free
If you prefer an open-source alternative, consider installing unrar-free. This version, however, has limitations, such as lacking support for RAR 4 or 5 formats. To install unrar-free, use this command:
sudo apt install unrar-free
Remember that unrar-free may not fully meet your needs if you frequently work with newer RAR formats. Also, note that the commands for unrar-free differ from those for the standard UNRAR package.
Basic UNRAR Commands
Extracting Files Without Preserving Paths
To extract files from a RAR archive without keeping the original directory structure, use:
unrar e archive.rar
Replace archive.rar with your RAR file’s name. This command extracts files directly to the current directory.
Listing Archive Contents
To view the contents of a RAR archive, use:
unrar l archive.rar
Replace archive.rar with your archive’s name. This command shows a list of files in the archive.
Printing File to Standard Output
For displaying the contents of a specific file within a RAR archive, use:
unrar p archive.rar file.txt
Replace archive.rar with your RAR file’s name and file.txt with the file you wish to view.
Testing Archive for Errors
To check a RAR archive for any errors or corruption, use:
unrar t archive.rar
Replace archive.rar with the archive you want to test. This ensures the integrity of the archive.
Verbosely Listing Archive Contents
For a detailed list of the contents of a RAR archive, including file sizes and compression info, use:
unrar v archive.rar
Replace archive.rar with your archive’s name. This provides comprehensive details about the files.
Extracting Files with Full Path
To extract files while preserving the entire directory structure, use:
unrar x archive.rar
Replace archive.rar with your RAR file’s name. This command maintains the original folder layout.
Extracting With Password
For extracting files from a password-protected RAR archive, use:
unrar x -ppassword archive.rar
Replace archive.rar with your file’s name and password with the actual password.
Excluding Specific Files During Extraction
To exclude a particular file while extracting, use:
unrar x -xfile_to_exclude.txt archive.rar
Replace archive.rar with your RAR file’s name and file_to_exclude.txt with the file you don’t want to extract.
Updating Files in an Archive
To update files within a RAR archive, use:
unrar u archive.rar
Replace archive.rar with your RAR file’s name. It updates only files older than those in the archive.
Setting Output Path for Extracted Files
To extract files to a specific location, use:
unrar x -op/destination/path/ archive.rar
Replace archive.rar with your file’s name and /destination/path/ with your desired extraction path.
Conclusion
By installing either unrar or unrar-free on your Ubuntu system, you ensure that you have the tools necessary to manage and extract RAR files efficiently. The proprietary unrar package provides the most comprehensive support for RAR files, while unrar-free offers a fully open-source option with basic functionality. Regular updates from Ubuntu’s repositories will keep these tools current, ensuring that your system remains capable of handling a wide range of compressed archives on Ubuntu.