I am new to cygwin, less than a week and I must say it is great. I’m not too familiar with linux either other than change dir, remove dir or file commands. But being able to run a Unix emulator such as cygwin is a great way to get familiarized with the unix environment.
That said, you are probably in the same shoes I found myself in a few minutes ago. During my install of cygwin, I installed 7zip. this is an archiving and compressed file extracting utility. A recent task of mine was to extract text files from compressed formats and perform a line count. Most of the files were .zip files until I came across some .rar files. I thought 7zip would handle them since it handles .rar files via the windows interface, but instead I received an error.
$ 7z e test.rar
7-Zip 9.04 beta Copyright (c) 1999-2009 Igor Pavlov 2009-05-30
p7zip Version 9.04 (locale=C,Utf16=off,HugeFiles=on,2 CPUs)
Can't load '/usr/lib/p7zip/Codecs/.keep-p7zip' (Permission denied)
Processing archive: test.rar
Extracting test_out.txt Unsupported Method
Sub items Errors: 1
The correct command to issue was unrar e test.rar. But without having that RAR utility for cygwin and cygwin not not offering it through their regular setup or additional installs you need to take the following steps to install RAR on cygwin.
- Click on setup.exe in your original cygwin folder. Usually it is c:\cygwin.
- Run through the setup as you did the first time until you come to the “Select Packages” screen.
- From the packages listed, select make and makedepend. These packages are listed under Devel (for development). Finish out the wizard (note – you will not lose anything you had previously installed).
- Go to http://www.rarlab.com/rar_add.htm and download the UNRar source files
- Save and extract the contents of the package under your home directory of your cygwin environment. (Once extracted, a folder named unrar will hold all the files)
- Start up your cygwin environment
- navigate to the unrar folder that contains all the source files for unrar. Then type make -f makefile.cygmin. This is the name of the file that will create an unrar.exe file in that same directory. Your cygwin console will inform you when it is complete. it usually takes a minute or two.
- Copy the resulting unrar.exe file to your c:\cygwin\bin\ directory (or wherever your root cygwin directory is).
- Now you are ready to uncompress your .rar file.
- To do this, navigate to the directory holding your .rar file.
- Type: unrar e name_of_rar_file.rar
That’s it. Once you use this, you will love it. The performance is great.
In response to the comments made below, I’ve attached a screenshot of the gcc components that I have installed that allow the users to create the unrar.exe file to be placed in your bin. Also here is a link to download my unrar.exe (compiled on my Windows 7 machine) file in case anyone wants to bypass the compiling step. I know I am trustworthy, but always virus scan anything you download from the web.

Thanks for the information. Just a note to help some, the source code is compiled using g++ therefor the gcc compiler must also be installed for these instructions to be successful.
This doesn’t cut it for me: am I doing something wrong?
$ make -f makefile.cygmin
g++ -mno-cygwin -O2 -Wno-deprecated -D_MSC_VER -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DUNRAR -c rar.cpp
g++: The -mno-cygwin flag has been removed; use a mingw-targeted cross-compiler.
Sorry I could not replicate your error, however as one person commented, you need to have the gcc compiler installed. I noticed that on my installation of cygwin, I have the following gcc components installed (see screenshot at bottom of post). The example was based off of an XP machine that I run at work, however at home I have a Windows 7 machine that I recently installed cygwin on and tried out.
At the bottom of the post I’ve placed a screenshot of the gcc packages I have installed.
I got the same error – the makefile doesn’t work with modern gcc.
You will have to install an older version of gcc – I have the below, and it works.
- gcc-3.4.4-3 (NOT 3.4.4-999
Thanks for your input.
I had success using the unix makefile on cygwin with the current cygwin g++ 4.3.4.
make -f makefile.unix
Yep that will work. The exe will have a depenancy on cygwin.dll (so you can’t use it on a machine without copying that as well). Or if you install MinGW you can change the g++ in the makefile.cygwin to mingw32-g++.
Thanks for the post BTW. I had a 50 rar files to extract and was surprized cygwin didn’t have unrar.
Compiled unrarsrc-4.0.3.tar.gz with gcc version 3.4.4 (make
-f makefile.unix) and it worked. Thanks!
Thanks… I’m trying to update my haipad tablet to android 2.2. the utility to update the firmware was rar’d. Your blog just made my life easier
The task can be solved more easily due to the following symbolic link
ln -s “/cygdrive/c/Program Files (x86)/WinRAR/Rar.exe” /usr/bin/rar
if WinRAR is already installed in your host-system (i.e. Windows 7). After creating of symbolic link like this the rar-command will be available in xterm under sygwin, and you can work with the RAR-archives directly from bash-scripts as well as under Linux Operating System itself.
ln -s to a native win32 binary will work but create problem when doing something like this
$ ./unrar.exe /cygdrive/j/cc/rarfile2extract.rar
or
$ find . -type f -name “*.rar” | xargs ….
you get the point.
You don’t need to compile unrar from source.
http://gnuwin32.sourceforge.net/packages/unrar.htm
On my Win7 x64 box, unrar.exe was installed in “C:\Program Files (x86)\GnuWin32\bin”. You can then run the executable from the cygwin bash CLI, by either (1) prepending the path, or (2) adding the path to the Windows “Path” environment variable. You will have to relaunch cygwin after the change for (2) to work.
I seem to have read this wrong… I installed p7zip from cygwin, and used 7z e as you said you did… it worked perfectly, but I wanted x instead of e. to preserve fodler structure.
Amazing to me is the fact that your post acutally said that 7z should not work and I understood it the otherway around and it worked.
thanks for the post