Install Unrar on Alpine Linux Container

This guide provides the exact commands required to install the unrar package inside an Alpine Linux container. You will learn how to use Alpine’s native package manager to quickly add the archive extraction tool while keeping the final container image lightweight and optimized.

The Installation Command

To install unrar inside an Alpine Linux container, use the Alpine package keeper (apk) with the --no-cache flag. Run the following command:

apk add --no-cache unrar

Using the --no-cache option is a container best practice. It downloads the package index directly from the remote repository, installs the package, and discards the cache index without storing it in /var/cache/apk/, keeping the container filesystem small.

Installing via Dockerfile

If you are building an automated container image, include the command in your Dockerfile:

FROM alpine:latest

RUN apk add --no-cache unrar

Enabling the Community Repository (If Needed)

In most standard Alpine environments, unrar is available directly through the community repository. If your container fails to locate the package with an unsatisfied constraints error, ensure the community repository is enabled in /etc/apk/repositories.

You can enable the community repository and install unrar in a single command:

apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/v$(cut -d. -f1,2 /etc/alpine-release)/community unrar

Verifying the Installation

After running the installation command, verify that the utility is accessible by checking its version:

unrar --version

Basic Extraction Usage

Once installed, extract a RAR archive using the x flag to preserve directory paths:

unrar x archive.rar