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

Last updated on December 15, 2020 by Dan Nanni

While a typical archive file relies on a separate program (e.g., tar, gunzip, 7z) 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.

Install makeself on Linux

To install makeself, 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.4.2. Copy all the shell scripts in the directory to /usr/bin.

$ wget
$ chmod 755
$ ./
$ cd makeself-2.4.2
$ 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

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

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean