Open RAR and 7z files on Mac from Terminal
Install Homebrew, run brew install unar, then unar archive.rar to extract a RAR or 7z file into the current folder. For 7z, brew install sevenzip gives you 7-Zip’s own 7zz command.
Archive Utility, the extractor built into macOS, can’t open RAR files (and opens 7z only on recent macOS releases), and Terminal’s unzip only handles ZIP. The usual fix takes two minutes. Install Homebrew, then run brew install unar, and unar archive.rar extracts the archive into the current folder. For 7z, 7-Zip’s own command-line tool is one more line away: brew install sevenzip, then 7zz x archive.7z.
If you’d rather not use Terminal at all, openrar.app opens RAR and 7z in the browser, and Mac archive apps compared lists the apps.
Step 1: Install Homebrew
Homebrew is the most widely used package manager for macOS: it installs command-line tools with a single command. Check whether you already have it:
brew --version
If you see a version number, skip to step 2. If you see command not found: brew, open brew.sh, copy the install command shown on the page, paste it into Terminal and press Return. At the time of writing it is:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The installer asks for your Mac password (nothing appears as you type, which is normal) and installs Apple’s Command Line Tools if they’re missing, which can take a few minutes.
On Apple silicon Macs, read the end of the installer’s output. It prints a “Next steps” section with commands that add Homebrew to your shell. Run them, or brew will still be “not found” afterwards. Then open a new Terminal window.
Step 2: Open RAR (and 7z) with unar
unar comes from the same engine as The Unarchiver. It reads RAR (RAR4 and RAR5), 7z, ZIP, TAR and many other formats.
brew install unar
This installs two commands: lsar to list what’s in an archive, and unar to extract it.
List the contents first
lsar archive.rar
Add -l for a longer listing with sizes and dates. Listing is a good habit with archives from unknown sources: you see what you’re about to unpack.
Extract
cd ~/Downloads
unar archive.rar
unar extracts into the current folder. If the archive has several items at its top level, it creates a folder named after the archive, so your Downloads folder doesn’t get flooded. Useful options:
unar -o ~/Desktop archive.rarextracts to another folder.unar -f archive.raroverwrites existing files without asking.unar -D archive.rarnever creates the enclosing folder.
File names with spaces
Terminal splits commands at spaces, so unar My Archive.rar fails. Either put the name in quotes, unar "My Archive.rar", or type unar (with a space) and drag the file from Finder into the Terminal window: Terminal pastes its full path, correctly escaped.
Password-protected archives
unar asks for the password when it needs one. You can also pass it with -p, but that leaves the password in your shell history, so letting it prompt is better. See how to open a password-protected RAR.
Split archives
Keep all the parts in one folder and run unar on the first one (archive.part1.rar, or archive.rar when the others are .r00, .r01…). It finds the rest itself. More in how to open split RAR files.
Alternative for 7z: 7-Zip’s 7zz
7-Zip’s author publishes a macOS build of the 7-Zip command-line tool, and Homebrew packages it as sevenzip:
brew install sevenzip
The command it installs is 7zz (not 7z, as older guides say). The essentials:
7zz l archive.7z # list the contents
7zz x archive.7z # extract, keeping folders
7zz x archive.7z -oOut # extract into the folder Out
7zz x archive.7z.001 # extract a split 7z archive
Note that there’s no space between -o and the folder name. Use x, not e: e dumps every file into one folder and loses the folder structure.
7zz can also create archives, which unar can’t: 7zz a backup.7z MyFolder makes a 7z of a folder. Adding -p -mhe=on asks for a password and encrypts the file names. 7-Zip for Mac covers it in more detail.
Common errors and fixes
zsh: command not found: brew. Homebrew isn’t installed, or the “Next steps” commands from the installer weren’t run. Install it or run those commands, then open a new Terminal window.
zsh: command not found: unar (or 7zz). The tool isn’t installed yet: run brew install unar or brew install sevenzip. If it says it’s already installed, the same PATH problem as above is the likely cause.
No such file or directory. Terminal is looking in the wrong folder or the name is misspelled. Use cd to go to the folder that holds the archive, or drag the file into the window to paste its exact path.
macOS asks whether Terminal may access your Downloads, Desktop or Documents folder. That’s macOS privacy protection. Allow it if you want to extract files there.
Wrong password, or a CRC or checksum error. A checksum error usually means the archive is incomplete or damaged: download it again. See what to do with a corrupt RAR file.
Missing volume. One part of a split archive is missing or renamed. Make sure every part is in the same folder, with its original name.
When Terminal isn’t the best tool
Terminal is ideal for scripts, servers and batches of archives. For the occasional download, a window is quicker: openrar.app opens RAR and 7z in any browser without installing anything, password-protected and split archives included, and OpenRAR for Mac adds archives of several gigabytes and Finder integration, free for personal use.