How to Install and Use the ‘unrar’ Command in Linux

How to Install and Use the ‘unrar’ Command in Linux

Linux terminal showing the installation of unrar a command for extracting RAR archives

Are you struggling with extracting RAR files on your Linux system? For many Linux users the task may seem daunting, however, the ‘unrar’ command can help! The ‘unrar’ command simplifies the process of extracting RAR files on your Linux system, making it worth learning to install and use. Luckily, it’s available on most package management systems, including APT for Debian and Ubuntu, and YUM for CentOS and AlmaLinux, making the installation straightforward once you know the steps.

In this guide, we will navigate you through the process of installing the ‘unrar’ command on your Linux system. We will provide you with installation instructions for both APT and YUM-based distributions, delve into how to compile ‘unrar’ from the source, and install a specific version. Finally, we will show you how to use the ‘unrar’ command and verify that the correctly installed version is in use.

Let’s dive in and start installing ‘unrar’ on your Linux system!

TL;DR: How Do I Install and Use the ‘unrar’ Command in Linux?

In most Linux distributions, you can install 'unrar' using the package manager. For instance, on Ubuntu, you can run the command sudo apt-get install unrar. Once installed, you can use it to extract a RAR file with unrar x filename.rar.

For example:

sudo apt-get install unrar
unrar x example.rar

# Output:
# UNRAR 5.50 freeware      Copyright (c) 1993-2017 Alexander Roshal

# Extracting from example.rar

# Extracting  example.txt                                            OK 
# All OK

This is a basic way to install and use the ‘unrar’ command in Linux, but there’s much more to learn about ‘unrar’. Continue reading for more detailed information, advanced installation options, and usage scenarios.

Understanding the ‘unrar’ Command and Its Installation Process

The ‘unrar’ command is a versatile tool in Linux that allows you to extract files from RAR archives. RAR, or Roshal Archive, is a proprietary file format that supports data compression, error recovery, and file spanning. It’s widely used for compressing and archiving files, especially in environments where space is a premium. The ‘unrar’ command allows you to unlock these files and access their contents.

To use the ‘unrar’ command, you first need to install it on your Linux system. The process varies slightly depending on the package manager your Linux distribution uses. We will cover the installation process using two of the most popular package managers: APT (used in Debian, Ubuntu, and related distributions) and YUM (used in CentOS, Fedora, and related distributions).

Installing ‘unrar’ with APT

If you’re using a Debian-based distribution like Ubuntu, you can install ‘unrar’ using the APT package manager. Here’s how you do it:

sudo apt update
sudo apt install unrar

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed:
# unrar-free
# The following NEW packages will be installed:
# unrar unrar-free
# 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
# Need to get 129 kB of archives.
# After this operation, 355 kB of additional disk space will be used.
# Do you want to continue? [Y/n]

The first command updates the package list on your system. The second command installs the ‘unrar’ package. The output shows that the ‘unrar’ package and its dependencies are installed successfully.

Installing ‘unrar’ with YUM

If you’re using a Red Hat-based distribution like CentOS, you can install ‘unrar’ using the YUM package manager. Here’s how:

sudo yum update
sudo yum install unrar

# Output:
# Loaded plugins: fastestmirror
# Loading mirror speeds from cached hostfile
# Resolving Dependencies
# --> Running transaction check
# ---> Package unrar.x86_64 0:5.4.5-1.el7 will be installed
# --> Finished Dependency Resolution
# Dependencies Resolved
# ================================================================================
# Package      Arch            Version                 Repository           Size
# ================================================================================
# Installing:
# unrar        x86_64          5.4.5-1.el7             epel                89 k
# 
# Transaction Summary
# ================================================================================
# Install  1 Package
# Total download size: 89 k
# Installed size: 154 k
# Is this ok [y/d/N]:

Like the APT commands, the first command updates the package list, and the second command installs the ‘unrar’ package. The output confirms that the ‘unrar’ package is installed successfully.

Installing ‘unrar’ from Source Code

To have more control over the installation process, you might want to install ‘unrar’ from its source code. Here’s how:

wget https://www.rarlab.com/rar/unrarsrc-5.9.4.tar.gz
tar -xvf unrarsrc-5.9.4.tar.gz
cd unrar
make -f makefile
sudo install -v -m755 unrar /usr/bin

# Output:
# ‘unrarsrc-5.9.4.tar.gz’ saved [227K]
# unrar/
# unrar/technote.txt
# unrar/unrar.cpp
# ...
# /usr/bin/unrar

This sequence of commands downloads the source code, extracts the files, compiles the source code, and installs the ‘unrar’ command.

Installing Specific Versions of ‘unrar’

From Source

To install a specific version of ‘unrar’ from source, you just need to modify the download URL. For example, to download version 5.8.5, you would use this URL: https://www.rarlab.com/rar/unrarsrc-5.8.5.tar.gz.

Using Package Managers

To install a specific version using APT or YUM, you can specify the version number in the install command. However, the version you want must be available in the repositories you’re using.

sudo apt-get install unrar=5.5.8
sudo yum install unrar-5.5.8

APT

To list all available versions in APT, use the apt-cache madison command:

apt-cache madison unrar

# Output:
# unrar | 1:5.5.8-1 | http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages

YUM

To list all available versions in YUM, use the yum --showduplicates list command:

yum --showduplicates list unrar

# Output:
# Available Packages
# unrar.x86_64 5.5.8-1.el7 epel

Version Comparison

Different versions of ‘unrar’ may have different features or compatibility with different systems. Here’s a brief comparison of some recent versions:

VersionKey ChangesCompatibility
5.9.4Added support for RAR5 archivesLinux 2.6 and later
5.8.5Improved speed for decompressing some types of archivesLinux 2.6 and later
5.5.8Added support for multi-threadingLinux 2.6 and later

Basic ‘unrar’ Usage and Verification

Using ‘unrar’

To extract all files from a RAR archive, you can use the x option:

unrar x archive.rar

# Output:
# Extracting from archive.rar
# Extracting  file.txt                                            OK 
# All OK

This command extracts all files from archive.rar into the current directory.

Verifying Installation

To verify that ‘unrar’ is installed correctly and check its version, you can use the unrar command with the -v option:

unrar -v

# Output:
# UNRAR 5.9.4 freeware      Copyright (c) 1993-2020 Alexander Roshal

This output confirms that ‘unrar’ version 5.9.4 is installed correctly.

Alternative Methods for Extracting RAR Files in Linux

While ‘unrar’ is a widely used tool for extracting RAR files in Linux, there are alternative methods available. Two of the most popular ones are ‘7zip’ and ‘tar’. These tools can come in handy when you’re dealing with different types of compressed files or if ‘unrar’ is not available or suitable for your needs.

Extracting RAR Files using ‘7zip’

‘7zip’ is a powerful file archiver with a high compression ratio. It supports a variety of archive formats, including RAR. Here’s how you can use ‘7zip’ to extract RAR files:

sudo apt-get install p7zip-full
7z x archive.rar

# Output:
# 7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
# p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,2 CPUs Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz (406E3),ASM,AES-NI)

# Scanning the drive for archives:
# 1 file, 40960 bytes (40 KiB)

# Extracting archive: archive.rar
# --
# Path = archive.rar
# Type = Rar
# Physical Size = 40960
# Everything is Ok

# Size:       20480
# Compressed: 40960

In this example, we first install the ‘p7zip-full’ package, which provides the ‘7z’ command. We then use the ‘7z’ command with the ‘x’ option to extract the files from archive.rar. The output confirms that the extraction process was successful.

Extracting RAR Files using ‘tar’

The ‘tar’ command is a traditional tool for dealing with archives in Linux. However, it doesn’t support RAR files out of the box. To use ‘tar’ for extracting RAR files, you need to install the ‘unrar’ package and use it as a plugin. Here’s how:

sudo apt-get install unrar
unrar p -inul archive.rar | tar x

# Output:
# UNRAR 5.5.8 freeware      Copyright (c) 1993-2017 Alexander Roshal

# Extracting from archive.rar
# Extracting  file.txt                                            OK 
# All OK

In this example, we use the ‘unrar’ command with the ‘p’ and ‘-inul’ options to pipe the contents of archive.rar to ‘tar’. The ‘tar’ command with the ‘x’ option then extracts the files. The output confirms that the extraction process was successful.

Comparison of ‘unrar’, ‘7zip’, and ‘tar’

ToolAdvantagesDisadvantages
‘unrar’Supports RAR files natively, easy to useDoesn’t support other archive formats
‘7zip’Supports a variety of archive formats, high compression ratioMore complex command syntax
‘tar’Traditional Linux tool, supports many archive formats with pluginsDoesn’t support RAR files natively

In conclusion, while ‘unrar’ is a great tool for dealing with RAR files, ‘7zip’ and ‘tar’ provide viable alternatives. The best tool for you depends on your specific needs and the types of files you’re dealing with.

Troubleshooting ‘unrar’ Command Issues

While the ‘unrar’ command is generally straightforward to use, you might encounter some issues, especially when dealing with different versions of Linux and RAR files. Here are some common problems and their solutions.

‘unrar’ Command Not Found

If you see an error message saying ‘unrar: command not found’, it means the ‘unrar’ package is not installed on your system. You can install it using your package manager as described in the previous sections. For example:

sudo apt-get install unrar

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following NEW packages will be installed:
# unrar
# 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
# Need to get 0 B/129 kB of archives.
# After this operation, 355 kB of additional disk space will be used.
# Selecting previously unselected package unrar.
# (Reading database ... 160975 files and directories currently installed.)
# Preparing to unpack .../unrar_1%3a5.5.8-1_amd64.deb ...
# Unpacking unrar (1:5.5.8-1) ...
# Setting up unrar (1:5.5.8-1) ...
# update-alternatives: using /usr/bin/unrar-nonfree to provide /usr/bin/unrar (unrar) in auto mode

This command installs the ‘unrar’ package on a Debian-based system. The output confirms that the ‘unrar’ package is installed successfully.

‘unrar’ Command Not Working with RAR5 Files

The ‘unrar’ command in some older Linux distributions may not support RAR5 files. If you encounter an error when trying to extract a RAR5 file, you can install the latest version of ‘unrar’ from the source code as described in the previous sections.

‘unrar’ Command Extracting Files to Wrong Directory

By default, the ‘unrar’ command extracts files to the current directory. If you want to extract files to a different directory, you can specify the directory path after the archive name. For example:

unrar x archive.rar /path/to/directory

# Output:
# Extracting from archive.rar
# Creating    /path/to/directory                                    OK
# Extracting  /path/to/directory/file.txt                           OK 
# All OK

This command extracts all files from archive.rar into /path/to/directory. The output confirms that the extraction process was successful.

Remember, the ‘unrar’ command is a powerful tool, but like any tool, it requires some understanding and practice. If you encounter an issue not covered here, don’t hesitate to consult the ‘unrar’ man page or other online resources.

Understanding File Compression and Decompression in Linux

File compression is a vital process in any operating system, including Linux. It allows you to reduce the size of files or directories, making them easier to store and share. Compression works by identifying and eliminating redundancy in data, effectively ‘shrinking’ the files.

In Linux, there are several tools for file compression, such as ‘gzip’, ‘bzip2’, and ‘zip’. Each of these tools uses a different algorithm for compression, resulting in varying levels of efficiency and speed.

gzip largefile.txt

# Output:
# largefile.txt.gz

In this example, the ‘gzip’ command compresses the file largefile.txt, resulting in a new, smaller file largefile.txt.gz. The original file is removed.

On the other hand, decompression is the process of restoring compressed files to their original form. This is where tools like ‘unrar’ come in. They can interpret the compressed data and reconstruct the original files.

gunzip largefile.txt.gz

# Output:
# largefile.txt

In this example, the ‘gunzip’ command decompresses the file largefile.txt.gz, resulting in the original file largefile.txt. The compressed file is removed.

The Role of ‘unrar’ in File Decompression

The ‘unrar’ command is specifically designed to decompress RAR files, a popular format for file compression. RAR files offer several advantages over other formats, such as support for password protection and error recovery. However, they require a specialized tool like ‘unrar’ for decompression.

unrar x archive.rar

# Output:
# Extracting from archive.rar
# Extracting  file.txt                                            OK 
# All OK

In this example, the ‘unrar’ command extracts all files from archive.rar into the current directory.

In conclusion, file compression and decompression are essential processes in Linux. They help manage disk space, facilitate file sharing, and even contribute to system security. Tools like ‘unrar’ play a crucial role in these processes, enabling users to handle RAR files with ease.

The Importance of File Compression and Decompression in System Administration and Security

The role of file compression and decompression extends beyond just saving disk space. It’s an essential part of system administration and security in Linux. For instance, system administrators often use compressed files for backups, software distribution, and data transfer. Compressed files take up less space, are faster to copy, and can be encrypted for added security.

# Example of creating a compressed backup

tar -czvf backup.tar.gz /path/to/directory

# Output:
# tar: Creating gzip compressed archive 'backup.tar.gz'
# tar: Adding '/path/to/directory' (from command line)
# tar: Adding '/path/to/directory/file1.txt' (from '/path/to/directory/file1.txt')
# tar: Adding '/path/to/directory/file2.txt' (from '/path/to/directory/file2.txt')

In this code block, we create a compressed backup of a directory using the ‘tar’ command with the ‘czvf’ options. The ‘c’ option creates a new archive, the ‘z’ option compresses it using gzip, the ‘v’ option makes the operation verbose, and the ‘f’ option specifies the archive file name.

Exploring Related Concepts: File Permissions in Linux

File permissions in Linux is another crucial concept related to system administration and security. It determines who can read, write, and execute files. Understanding file permissions can help you manage files more effectively, especially when dealing with sensitive data or system files.

# Example of changing file permissions

chmod 755 filename.txt

# Output:
# -rwxr-xr-x 1 user group 0 Jan  1 00:00 filename.txt

In this code block, we change the permissions of a file using the ‘chmod’ command. The ‘755’ argument sets the permissions to ‘rwxr-xr-x’, which means the owner can read, write, and execute the file, while other users can only read and execute it.

Further Resources for Mastering ‘unrar’ and Related Concepts

To delve deeper into the topics discussed in this guide, you can check out the following resources:

  1. The Linux Information Project provides a wealth of information on various Linux topics, including file compression and file permissions.

  2. The Linux Command Line by William Shotts is a comprehensive book that covers many aspects of the Linux command line, including file management and system administration.

  3. The RARLAB website offers detailed information on the ‘unrar’ command and RAR files, including the latest updates and technical notes.

Wrapping Up: Installing the ‘unrar’ Command in Linux

In this comprehensive guide, we’ve navigated the process of installing and using the ‘unrar’ command in Linux, a powerful tool for extracting RAR files. We’ve covered everything from the basic installation process to advanced usage scenarios, providing a thorough understanding of the ‘unrar’ command.

We began with the basics, explaining how to install the ‘unrar’ command in both APT and YUM-based Linux distributions. We then delved into advanced usage, discussing how to install ‘unrar’ from source, install specific versions, and use the ‘unrar’ command to extract files from a RAR archive. We also tackled common issues that you might encounter when using the ‘unrar’ command and provided solutions for each problem.

We also explored alternative approaches to handle RAR file extraction in Linux, such as using ‘7zip’ or ‘tar’. Each method was explained with practical code examples, and we compared their advantages and disadvantages to help you make an informed choice.

ToolAdvantagesDisadvantages
‘unrar’Supports RAR files natively, easy to useDoesn’t support other archive formats
‘7zip’Supports a variety of archive formats, high compression ratioMore complex command syntax
‘tar’Traditional Linux tool, supports many archive formats with pluginsDoesn’t support RAR files natively

Whether you’re a beginner just starting out with Linux or a seasoned system administrator, we hope this guide has given you a deeper understanding of the ‘unrar’ command and its importance in file compression and decompression. With this knowledge, you’re well-equipped to handle RAR files in Linux. Happy extracting!