3

This is a more specific question of How to open rar file in linux (asked in 2015) that had no detailed answer for p7zip to open RAR files at this time of writing.

p7zip is essentially the 7-zip archive manager on Linux, except that does not include the graphical interface. p7zip should be able to open RAR files like 7-zip does, but some recently downloaded RAR files can not be opened using p7zip. The RAR file itself is not broken for sure.

This question may cover the following sub-questions (without the question marks, as not to be confused with the main question), which are relevant to explain the how-to:

  • Does p7zip really support RAR format
  • Which package to install for p7zip to support RAR format, and which repository would provide the package
  • Which binary of 7z, 7za, or 7zr can open the RAR file
  • Can p7zip be used to open the RAR file via graphical interface
  • When using p7zip to open the RAR file, the command failed with message "Error: Can not open file as archive", then how to solve

So how to use p7zip to open RAR files?

This is a self-answer question that has been written like a new question, which was created based on the discussion in this meta post. Should there be more than one answer, the most accurate and most complete answer will be accepted after some time (not immediately).

  • 2
    I would say self answers are pretty normal here, I myself have quite maybe around 100, and I am not a rare case. You might not need that disclaimer. – Rui F Ribeiro Jun 5 at 6:32
  • I definitely have less but have already done that several time as well. – Kiwy Jun 6 at 10:27
6

p7zip is the Unix command-line port of 7-Zip, which has many supported formats. p7zip supports RAR format for unpacking or extract only. User can either download the binaries and source code or install the packages provided by Linux distributions and other supported systems.

With the binaries and source code, p7zip is available in a single download file that can handle all supported formats and installation is optional. That means the command-line tool can be run as soon as the download file (tar.bz2) is extracted by a native archive manager on Linux.

With the packages, p7zip will require separate packages to handle all supported formats and installation is necessary. For Debian (and Ubuntu), p7zip is available in three different packages from the repositories. Ensure that the main and non-free respositories (or universe and multiverse repositories for Ubuntu) are enabled and updated first.

Install the required package 'p7zip-rar' that will additionally include 'p7zip-full' as one of the package dependencies; the other package 'p7zip' is not required at all.

sudo apt-get install p7zip-rar

Then run the 7z command to extract the RAR file.

7z x filename.rar

Short explanation: p7zip provides 7zr command that can only handle 7z archives. p7zip-full provides 7z command that can handle more supported formats and p7zip-rar is required for 7z to handle RAR archives.

Note the following use cases:

  • 7zr and 7za commands will not work and only 7z command will work with the RAR format. p7zip on ArchWiki has noted the difference between 7z, 7za and 7zr binaries.
  • 7z can be used with any of the supported graphical file archivers, including file-roller, ark, xarchiver, engrampa. Just install one of the supported archive managers to use p7zip via graphical interface, and no further configuration is needed.
  • Newer version of RAR files (notably RAR version 5) should be unpacked or extracted using a newer version of p7zip (at least 16.02), otherwise p7zip will return error and failed to open the file.

Example output of p7zip (9.20) failed to test open a RAR file (Rar5):

$ 7z t sample.rar 

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,1 CPU)

Processing archive: sample.rar

Error: Can not open file as archive

Example output of p7zip (16.02) successfully test open a RAR file (Rar5):

$ p7zip_16.02/bin/7z t sample.rar 

7-Zip [32] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M processor         1.60GHz (6D8),ASM)

Scanning the drive for archives:
1 file, 483579957 bytes (462 MiB)

Testing archive: sample.rar
--
Path = sample.rar
Type = Rar5
Physical Size = 483579957
Solid = -
Blocks = 5
Encrypted = -
Multivolume = -
Volumes = 1

Everything is Ok

Files: 5
Size:       498584235
Compressed: 483579957

The latter output of p7zip (16.02) had included the line Type = Rar5 that indicates the RAR version 5. The file command may contain similar but less human readable information of RAR version.

$ file *.rar 
sample4.rar: RAR archive data, v1d, os: Unix
sample.rar:  RAR archive data, va6, flags: Archive volume, Commented, Locked, os: Unix

Notice that the older RAR file (Rar) by default had included v1d whilst the newer RAR file (Rar5) had included va6 within the description of each file. To this answered date, no relevant information to determine whether the file descriptions correspond to the RAR versions or not.

TL;DR p7zip can open RAR files, provided the package (p7zip-rar), the command (7z), and the newer version (16.02+ for Rar5 support) are used to handle the RAR format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.