Install Rar and Unrar in Linux
RAR is a file compression format and archive utility commonly used for compressing and decompressing files. It stands for “Roshal Archive” named after its creator, Eugene Roshal. RAR files are similar to ZIP files but often provide higher compression ratios, making them useful for reducing the size of large files or collections of files.
RAR files can contain one or more files or directories, and they are typically used to bundle multiple files into a single archive for easier storage or distribution. RAR archives can also be encrypted with passwords to protect the contents from unauthorized access.
To create or extract RAR files, you need software that supports the RAR format. One popular tool for working with RAR files is WinRAR, available for Windows. RAR files are archived by Winrar compression software and can be split into large files.
Please note that RAR is a proprietary format, and while there are free software options available, the RAR compression algorithm itself is not open-source.
Windows support for the WinRAR tool has made it easier for users to manage compressed files, but unfortunately, Linux users cannot use the WinRAR tool in Linux by default; Therefore, to extract and compress RAR files, they must install Rar and Unrar commands line tools in Linux.
In this article, we will teach how to install Rar and Unrar in popular Linux distributions through official binary tar files in Linux to extract RAR archive, decompress or unrar a file. If you intend to install Rar and Unrar command line tools on the server, you must first purchase a Linux VPS and then follow the instructions in this article. If you are ready, without wasting time, let’s start the installation process.
Unrar installation on Linux
By following the instructions that we will teach later, you can also manage compressed files by installing Rar and Unrar command line tools in Popular Linux distributions such as Debian, Ubuntu, CentOS, and Fedora.
- To install Unrar in Debian and Ubuntu-based distributions, run the following command using the apt package manager:
sudo apt-get install unrar
Or
sudo apt install unrar
- To install Unrar on RHEL-based distributions, use the following commands:
On RHEL-based Linux :
sudo yum install unrar
sudo yum install epel-release
On Fedora Linux:
sudo dnf install unrar
If the Linux distribution you are using does not support the Unrar package by default, you must download the latest unrar/rar file using the Wget command:
On 64-bit:
# cd /tmp
# wget https://www.rarlab.com/rar/rarlinux-x64-5.7.1.tar.gz
On 32-bit:
# cd /tmp
# wget https://www.rarlab.com/rar/rarlinux-x32-621.tar.gz
Then extract the downloaded file using the Tar command:
On 64-bit:
# tar -zxvf rarlinux-x64-621.tar.gz
On 32-bit:
# tar -zxvf rarlinux-x32-621.tar.gz
Run the following commands and set the environment variables by copying the Rar and Unrar files to /usr/local/bin/:
# cd rar
# sudo cp -v rar unrar /usr/local/bin/
You can run these commands in your terminal to confirm the functionality of the Rar and Unrar applications:
[root@linuxzone ~]# rar
RAR 5.71 Copyright (c) 1993-2019 Alexander Roshal 28 Apr 2019
Trial version Type 'rar -?' for help
Usage: rar <command> -<switch 1> -<switch N> <archive> <files...>
<@listfiles...> <path_to_extract\>
<Commands>
a Add files to archive
c Add archive comment
ch Change archive parameters
cw Write archive comment to file
d Delete files from archive
e Extract files without archived paths
.
.
.
.
Rar installation on Linux
Run the following commands to install the rar command line tool:
Install rar on Debian/Ubuntu:
sudo apt install rar
Install rar on RHEL/CentOS/Fedora/Rocky Linux/Alma Linux:
sudo yum install rar
Sample output:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Dependencies Resolved
=========================================================================================
Package Arch Version Repository Size
=========================================================================================
Installing:
rar i386 3.8.0-1.el5.rf rpmforge 264 k
Transaction Summary
=========================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 264 k
Is this ok [y/N]: y
Downloading Packages:
rar-3.8.0-1.el5.rf.i386.rpm | 264 kB 00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : rar 1/1
How to manage compressed files using Rar/Unrar
After installing the Rar and Unrar command line tools in Linux, you can use the features of this tool to manage compressed files in Linux, for which we will provide you with the necessary training.
Extracting RAR files in Linux
The .rar file extension refers to a specific file format known as a RAR archive. It is a compressed file format created using the RAR compression algorithm. RAR archives are commonly used for bundling multiple files or directories into a single file, making it easier to store, transfer, or share them.
RAR archives can achieve higher compression ratios compared to other formats, resulting in smaller file sizes. This can be especially useful when dealing with large files or when you want to reduce the overall size of a collection of files.
To extract compressed files with the extension .rar in the Linux destination directory, run the following command using the rar command line tool:
unrar e filename.rar /home/
Sample output:
UNRAR 4.20 beta 3 freeware Copyright (c) 1993-2012 Alexander Roshal
Extracting from Opera.rar
Extracting index.php OK
Extracting index.html OK
Extracting xyz.txt OK
Extracting abc.txt OK
All OK
To open the Rar file with its original directory structure, you must use the unrar x option and the following command:
unrar x filename.rar
Sample output:
UNRAR 4.20 beta 3 freeware Copyright (c) 1993-2012 Alexander Roshal
Extracting from Opera.rar
Creating Opera OK
Extracting Opera/index.php OK
Extracting Opera/index.html OK
Extracting Opera/xyz.txt OK
Extracting Opera/abc.txt OK
Creating default OK
Extracting default/index.php OK
Extracting default/index.html OK
Creating include OK
Extracting include/abc.txt OK
Creating php OK
Extracting php/xyz.txt OK
All OK
Testing the RAR file in Linux
Using the unrar tool and the unrar t option, you can test the integrity of the archive file you downloaded from the Internet. Therefore, to check the contents of the archive file, run the following command:
unrar t filename.rar
Sample output:
UNRAR 4.20 beta 3 freeware Copyright (c) 1993-2012 Alexander Roshal
Testing archive Opera.rar
Testing Opera/index.php OK
Testing Opera/index.html OK
Testing Opera/xyz.txt OK
Testing Opera/abc.txt OK
Testing default/index.php OK
Testing default/index.html OK
Testing include/abc.txt OK
Testing php/xyz.txt OK
All OK
Accessing and organizing RAR file content in Linux
Rar compressed files contain several large files. Run the following command to list the contents of the archive file by time, creation date, size, name, and permissions:
unrar l filename.rar
Sample output:
UNRAR 4.20 beta 3 freeware Copyright (c) 1993-2012 Alexander Roshal
Archive Opera.rar
Name Size Packed Ratio Date Time Attr CRC Meth Ver
-------------------------------------------------------------------------------
index.php 0 8 0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
index.html 0 8 0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
xyz.txt 0 8 0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
abc.txt 0 8 0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
index.php 0 8 0% 18-08-12 19:22 -rw-r--r-- 00000000 m3b 2.9
index.html 0 8 0% 18-08-12 19:22 -rw-r--r-- 00000000 m3b 2.9
abc.txt 0 8 0% 18-08-12 19:22 -rw-r--r-- 00000000 m3b 2.9
xyz.txt 0 8 0% 18-08-12 19:22 -rw-r--r-- 00000000 m3b 2.9
-------------------------------------------------------------------------------
8 0 64 0%
Creating a RAR file in Linux
The Unrar tool is helpful in testing, extracting, and listing archive files. you must use the Rar tool, to create compressed files or Rar archives in Linux. As a result, using the following command, you can create a Rar file for the directory you want in Linux:
rar a filename.rar filename1
By executing the previous command, you can create a rar file named filename in the filename1 directory.
Sample output:
RAR 3.80 Copyright (c) 1993-2008 Alexander Roshal 16 Sep 2008
Shareware version Type RAR -? for help
Evaluation copy. Please register.
Creating archive Opera.rar
Adding Opera/index.php OK
Adding Opera/index.html OK
Adding Opera/xyz.txt OK
Adding Opera/abc.txt OK
Adding Opera OK
Done
Updating or adding files to the Archive
rar u option is used to update or add files to the existing archive file. For this purpose, run the following command:
rar u filename.rar filename2.sql
Sample output:
RAR 3.80 Copyright (c) 1993-2008 Alexander Roshal 16 Sep 2008
Shareware version Type RAR -? for help
Evaluation copy. Please register.
Updating archive Opera.rar
Adding Opera2.sql OK
Done
To ensure adding the filename2.sql file and updating the contents of the archive file, run the following command:
rar l filename.rar
Deleting files from the archive in Linux
If you want to delete a file from the archive, use the rar d option:
rar d filename.rar
Recovering archive file
Whenever you decide to access the file archive that has been deleted, the rar r option will help you recover the file archive that has been lost:
rar r filename.rar
Locking Archives
Using the Rar tool, For improving security, you can lock an archive file. For this purpose, use the following command:
rar k filename.rar
Sample output:
RAR 3.80 Copyright (c) 1993-2008 Alexander Roshal 16 Sep 2008
Shareware version Type RAR -? for help
Processing archive Opera.rar
Locking archive
Done
Setting a password for the archive
To protect your important information in the archive files, the Rar tool allows you to set a password for the archive. To set the password for the archive file, use the rar a -p option:
rar a -p filename.rar
Sample output:
Enter password (will not be echoed):
Reenter password:
AR 3.80 Copyright (c) 1993-2008 Alexander Roshal 16 Sep 2008
Shareware version Type RAR -? for help
Evaluation copy. Please register.
Updating archive Opera.rar
Updating Opera.sql OK
Done
To ensure the password is set for the archive file, extract the archive file again by running the following command:
rar x filename.rar
By running the previous command to open the archive file, you will check whether you are asked for the password you have set or not.
rar x Opera.rar
RAR 3.80 Copyright (c) 1993-2008 Alexander Roshal 16 Sep 2008
Shareware version Type RAR -? for help
Extracting from Opera.rar
Creating Opera OK
Extracting Opera/index.php OK
Extracting Opera/index.html OK
Extracting Opera/xyz.txt OK
Extracting Opera/abc.txt OK
Enter a password (will not be echoed) for Opera2.sql:
Extracting Opera2.sql OK
All OK
FAQ
How can I determine whether unrar is installed on Linux?
You can determine whether unrar is installed by running the unrar terminal command.
what is the difference between ZIP and RAR?
ZIP files take longer to compress than RAR files do. When it comes to file compression, RAR is superior to ZIP.
Conclusion
The Rar/Unrar command-line tool is one of the best tools for managing compressed files in Rar format. The RAR tool provides valuable facilities for creating, deleting, and adding RAR files and protecting files by locking the archive file and setting a password for them. The Unrar command-line tool also equips you to open, list, and test archive files. As a result, using the Rar/Unrar command-line tool helps optimize the management of compressed files in Linux.
In this article, you learned how to install Rar and Unrar tools in Linux, in addition, you learned how to use Rar and Unrar to manage compressed files. #man unrar
and #man rar
commands provide more explanations and options on how to use Rar/Unrar tools.
If you have a new and different experience of using rar and unrar commands, you can share your experience with us and other users.
Thank you for choosing our article to read.
Such beautiful writing this is. I appreciate your talent.