Never Ending Security

It starts all here

Tag Archives: Self-Extracting

How to Create a Self-Extracting Archive or Installer on Linux

Self-Extracting Archive

Archive files usually relies on a specialized program like tar or gunzip to extract content from it. A self-extracting (SFX) archive is like an executable. It can self-extract its content simply upon running. On the other hand, we have a self-extracting installer that does the same thing, but it also copies the content to appropriate directories.

In this article, we will explain how to create a self-extracting archive or installer on Linux. To pull this off we will use a command-line utility called makeself. There are other solutions out there as well, you may want to do some more research  after you try this approach. You may want  suggest a new way to this in the comment area bellow or publish your own article ( just log in and start publishing ). is a small shell script that generates a self-extractable tar.gz archive from a directory. The resulting file appears as a shell script (many of those have a .run suffix), and can be launched as is. The archive will then uncompress itself to a temporary directory and an optional arbitrary command will be executed (for example an installation script). This is pretty similar to archives generated with WinZip Self-Extractor in the Windows world. Makeself archives also include checksums for integrity self-validation (CRC and/or MD5 checksums).

The script itself is used only to create the archives from a directory of files. The resultant archive is actually a compressed (using gzip, bzip2, or compress) TAR archive, with a small shell script stub at the beginning. This small stub performs all the steps of extracting the files, running the embedded command, and removing the temporary files when it’s all over. All what the user has to do to install the software contained in such an archive is to “run” the archive, i.e sh I recommend using the “run” (which was introduced by some Makeself archives released by Loki Software) or “sh” suffix for such archives not to confuse the users, since they know it’s actually shell scripts (with quite a lot of binary data attached to it though!).

To install makeself on Linux, download the latest version in an archive format, and extract the downloaded archive as follows. Once the archive has extracted itself, it will create a new directory called makeself-2.1.5. Copy all the shell scripts in the directory to /usr/bin.

$ wget
$ chmod 755
$ ./
$ cd makeself-2.1.5
$ sudo cp *.sh /usr/bin

The basic usage of is as follows. [options] [directory_to_package] [sfx_archive_filename]  [startup_script] [optional_script_args]

The “label” argument is the message to print while an SFX archive is uncompressed. The “startup_script” specifies the script/command to launch after an SFX archive is successfully extracted. This is useful when you create a self-extracting installer. Typically a start-up script will copy/install the extracted content to appropriate target directories. The start-up script must be located inside the directory to package, so that the script is included in the SFX archive. Here are some of available options for

  • –gzip : Use gzip for compression (default option).
  • –bzip2 : Use bzip2 for compression.
  • –nocomp : Do not compress.
  • –notemp : Do not extract files into a temporary directory, but in a new sub-directory created in the current directory.
  • –follow : Follow all symbolic links, and archive files that are symbolic-linked.

Create a Self-Extracting Archive

To create a self-extracting archive which contains all files inside ./backup directory, do the following. Here the start-up routine does nothing more than printing “Extraction done”.

$ --notemp ./backup ./ "SFX archive for backup" echo "Extraction done"
Header is 403 lines long

About to compress 1540 KB of data...
Adding files to archive named "./"...
CRC: 2238411397
MD5: 0b0fd3a2ba08ffcec821b9cbaa11b70d

Self-extractible archive "./" successfully created.

To extract files from the archive, simply execute the archive:

$ ./
Creating directory backup
Verifying archive integrity... All good.
Uncompressing SFX archive for backup.............

Create a Self-Extracting Installer

If you want to create a self-extracting installer, you need to prepare a separate start-up script which will do the installation upon file extraction.

$ vi ./program/
if [ -d $HOME/bin ]
    cp myprogram $HOME/bin/

Then make the start-up script executable.

$ chmod 755 ./program/

Go ahead and create a self-extracting installer, and package the start-up script along with it as follows.

$ ./program ./ "SFX installer for program" ./

Download configuration at: