How to Install Unrar on FreeBSD

This guide provides a straightforward walkthrough for installing the unrar utility on FreeBSD to extract RAR archive files. It covers the two primary installation methods supported by FreeBSD: the binary package manager (pkg) for a quick and standard setup, and the FreeBSD Ports Collection for compiling the tool directly from source.

Method 1: Installing via the Package Manager (pkg)

Using the binary package manager is the fastest and recommended method for most users because it downloads and installs pre-compiled binaries.

  1. Open your terminal and switch to root (or use sudo).
  2. Update the local package repository catalog:
    pkg update
  3. Install the unrar package:
    pkg install unrar
  4. When prompted to proceed with fetching and installing the package, type y and press Enter.

Method 2: Installing via the Ports Collection

If you prefer to compile software from source or need custom build options, you can use the FreeBSD Ports Collection.

  1. Ensure your ports tree is up to date. If not already extracted, fetch it using:
    portsnap fetch extract
    (Or portsnap fetch update if previously extracted).
  2. Navigate to the unrar port directory:
    cd /usr/ports/archivers/unrar
  3. Compile and install the port:
    make install clean

Verifying the Installation

After completing either installation method, verify that unrar is properly installed by checking its version and help menu:

unrar

Basic Usage

To extract a RAR archive while preserving the internal directory structure, run:

unrar x archive_name.rar

To extract files into the current directory without subdirectories, run:

unrar e archive_name.rar