如何在 Ubuntu Linux 中使用 RAR 文件
rar unrar 压缩 解压
[RAR](https://www.rarlab.com/rar_file.htm) 是一种非常好的归档文件格式。但相比之下 7-zip 能提供了更好的压缩率，并且默认情况下还可以在多个平台上轻松支持 Zip 文件。不过 RAR 仍然是最流行的归档格式之一。然而 [Ubuntu](https://www.ubuntu.com/) 自带的归档管理器却不支持提取 RAR 文件，也不允许创建 RAR 文件。


办法总比问题多。只要安装 `unrar` 这款由 [RARLAB](https://www.rarlab.com/) 提供的免费软件，就能在 Ubuntu 上支持提取 RAR 文件了。你也可以安装 `rar` 试用版来创建和管理 RAR 文件。


![RAR files in Ubuntu Linux](/data/attachment/album/201810/03/213910k2ll1y2blbx939c1.png)


### 提取 RAR 文件


在未安装 `unrar` 的情况下，提取 RAR 文件会报出“未能提取”错误，就像下面这样（以 [Ubuntu 18.04](https://itsfoss.com/things-to-do-after-installing-ubuntu-18-04/) 为例）：


![Error in RAR extraction in Ubuntu](/data/attachment/album/201810/03/213910gy0e11qn7xv5evrz.jpg)


如果要解决这个错误并提取 RAR 文件，请按照以下步骤安装 `unrar`：


打开终端并输入：



```
sudo apt-get install unrar
```

安装 `unrar` 后，直接输入 `unrar` 就可以看到它的用法以及如何使用这个工具处理 RAR 文件。


最常用到的功能是提取 RAR 文件。因此，可以**通过右键单击 RAR 文件并执行提取**，也可以借助此以下命令通过终端执行操作：



```
unrar x FileName.rar
```

结果类似以下这样：


![Using unrar in Ubuntu](/data/attachment/album/201810/03/213910zbwcngjbdnga1c3z.jpg)


如果压缩文件没放在家目录中，就必须使用 `cd` 命令移动到目标目录下。例如 RAR 文件如果在 `Music` 目录下，只需要使用 `cd Music` 就可以移动到相应的目录，然后提取 RAR 文件。


### 创建和管理 RAR 文件


![Using rar archive in Ubuntu Linux](/data/attachment/album/201810/03/213911p3z0gv83waexz81a.jpg)


`unrar` 不允许创建 RAR 文件。因此还需要安装 `rar` 命令行工具才能创建 RAR 文件。


要创建 RAR 文件，首先需要通过以下命令安装 `rar`：



```
sudo apt-get install rar
```

按照下面的命令语法创建 RAR 文件：



```
rar a ArchiveName File_1 File_2 Dir_1 Dir_2
```

按照这个格式输入命令时，它会将目录中的每个文件添加到 RAR 文件中。如果需要某一个特定的文件，就要指定文件确切的名称或路径。


默认情况下，RAR 文件会放置在**家目录**中。


以类似的方式，可以更新或管理 RAR 文件。同样是使用以下的命令语法：



```
rar u ArchiveName Filename
```

在终端输入 `rar` 就可以列出 RAR 工具的相关命令。


### 总结


现在你已经知道如何在 Ubuntu 上管理 RAR 文件了，你会更喜欢使用 7-zip、Zip 或 Tar.xz 吗？


欢迎在评论区中评论。




---


via: <https://itsfoss.com/use-rar-ubuntu-linux/>


作者：[Ankush Das](https://itsfoss.com/author/ankush/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[HankChow](https://github.com/HankChow) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

[RAR](https://www.rarlab.com/rar_file.htm?ref=itsfoss.com) is a quite good archive file format. It is one of the most popular archive formats.

By default, Ubuntu's archive manager does not support extracting RAR files nor does it let you create RAR files. It would rather show you this error:

*There is no command installed for RAR archive files. Do you want to search for a command to open this file?*

![Ubuntu RAR File Error](https://itsfoss.com/content/images/wordpress/2012/07/Ubuntu-Rar-File-Error.png)

Sometimes extracting RAR files will show you "* Extraction not performed" error*.

![Error in RAR extraction in Ubuntu](https://itsfoss.com/content/images/wordpress/2018/08/extract-rar-error.jpg)

Fret not. We have a solution for you. To enable the support to extract RAR files, you need to install **UNRAR** – which is a freeware by [RARLAB](https://www.rarlab.com/?ref=itsfoss.com). And, to create and manage RAR files, you need to install **RAR**.

## Install RAR support in Ubuntu

Launch the terminal and type in the following command to make sure you have [multiverse repository enabled in Ubuntu](https://itsfoss.com/ubuntu-repositories/):

`sudo add-apt-repository multiverse`


Update the package cache:

`sudo apt update`


Now, **if you just want to extract RAR files** in Ubuntu, simply install the unrar package like this:

`sudo apt install unrar`


If you also want to create RAR files, you should install this file.

`sudo apt install rar`


## Extracting RAR Files in Ubuntu Linux

After installing unrar, you may choose to type in “**unrar**” (without the inverted commas) to know more about its usage and how to use RAR files with the help of it.

The most common usage would obviously be extracting the RAR file you have. So, **you can either perform a right-click on the file and proceed to extract it** from there or you can do it via the terminal with the help of this command:

`unrar x FileName.rar`


You can see that in action here:

![Using unrar in Ubuntu](https://itsfoss.com/content/images/wordpress/2018/08/unrar-rar-extraction.jpg)

If the file isn’t present in the Home directory, then you have to navigate to the target folder by [using the cd command in Linux](https://linuxhandbook.com/cd-command-examples/?ref=itsfoss.com). For instance, if you have the archive in the Music directory, simply type in “**cd Music**” to navigate to the location and then extract the RAR file.

## Creating & Managing RAR files in Ubuntu Linux

UNRAR does not let you create RAR files. So, you need to install the RAR command-line tool to be able to create RAR archives.

To do that, you need to type in the following command:

`sudo apt-get install rar`


Here, we will help you create a RAR file. In order to do that, follow the command syntax below:

`rar a ArchiveName File_1 File_2 Dir_1 Dir_2`


When you type a command in this format, it will add every item inside the directory to the archive. In either case, if you want specific files, just mention the exact name/path.

By default, the RAR files reside in **HOME** directory.

![Using rar archive in Ubuntu Linux](https://itsfoss.com/content/images/wordpress/2018/09/rar-update-create.jpg)

In the same way, you can update/manage the RAR files. Just type in a command using the following syntax:

`rar u ArchiveName Filename`


To get the list of commands for the RAR tool, just type “**rar**” in the terminal.

## Wrapping Up

Now that you’ve known how to use RAR files on Ubuntu, will you prefer using it over 7-zip, Zip, or Tar.xz?

Let us know your thoughts in the comments below.