How to create a self-extracting archive or installer in Linux

While a typical archive file relies on a separate program (e.g., tar, gunzip) to extract content from the archive file, a self-extracting (SFX) archive is an executable itself, and can self-extract its content simply upon running. A self-extracting installer does the same thing, but it also copies the extracted content to appropriate directories.

In this tutorial, I will explain how to create a self-extracting archive or installer on Linux.

For this purpose, you can use a command-line utility called makeself. The makeself tool is a shell script which creates a compressed TAR archive out of input directories/files, and adds a small shell script stub at the beginning of the archive to initiate self-extraction, and guide installation of extracted files.

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] [label] [startup_script] [optional_script_args]

The "label" argument is the message to print while an SFX archive is uncompressed.

The "startup_script" argument 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. Here I assume that the program directory to package is located at ./program. So prepare a start-up script inside ./program directory.

$ 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" ./

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

7 thoughts on “How to create a self-extracting archive or installer in Linux

  1. I think the most useful place for SFX is for easily installing programs for my own use (in my own home directory) rather than needing to have root (or sudo) access). It would be nice if it also included (by default) an 'uninstall' option. One of my biggest complaints on linux is when I install a program without any available .deb file (e.g. newest version of Adobe Acrobat Reader) and not being sure how to cleanly uninstall it, especially if root (or sudo) was needed to install it in the first place.

    To be honest, while using .deb, .rmp, Pacman, .tgz (Slackware) etc. to install the applications I want, is convenient and relatively save, actually producing (and testing) all of these versions (and others like PETget or Equo) for my new Linux program is a pain!

    It might be nice (in terms of security) if makeself would by default check and ensure that the resulting SFX can never be run as root? Since root can always do everything on Linux/UNIX this will probably not be possible or really useful against malicious programmers, but might at least prevent some accidental security issues (i.e. overwriting some .so file with a version that is incompatible with the distro default).

  2. (Win-)RAR is far superior compression and feature wise to every archival tool available under Linux, recently tested.

    And the installation of external programs (NOT from reprositories) is THE key feature of personal computing. Linux as Unix misses this feature up to now, and stays therefore in the IT medieval of the seventies with mainframes and workstations.

  3. Call me old fashioned, but why do I need an sfx on Linux? There are much cleaner ways for installing software on every Linux distribution.?

  4. The best way is "don't do it." Those are huge security risks and only ever got popular in the first place because Windows doesn't ship with proper compression or archival tools.

    • I agree that the main problem of self-extracting archives, especially blob installers run with superuser privilege, is their potential security risks. You will have to trust whoever provides SFX archives.

  5. Thank you!
    Your post was very helpful (to find makeself at first, and to use it after).
    I was creating an installer for Virtual Volumes View, and makeself was a great help at the way to distribute the resulting self extracting and installation archive.
    My installer was a text installer and now acts (almost) like Nvidia ones.
    Thanks again for the guidance.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *