How to Install tar.gz File on Ubuntu/Linux?


In Ubuntu/Other Linux distros, the “tar.gz” file is the combination of two techniques, i.e., “tar” an archive file format, and “gz” a compression technique. The “gz” compresses the files individually which takes up larger space whereas the “.tar” carries the files as a package/directory and then “gz” compresses it which takes less space. Thus, a “tar.gz” file is space efficient methodology than a simple “tar” or a “gz”.

The “tar.gz” files are used to serve multiple purposes and installing an application is one of them. Especially, when the installation depends on tens of files.

We are here with a detailed guide on installing a tar.gz file on Ubuntu/Linux.

How to Install tar.gz File on Ubuntu/Linux?

Installing any package/application through “tar.gz” depends on the files/package type compressed. Usually, the source code packages are compressed in the “tar.gz” format. However, you might occasionally get an “AppImage” or a “deb” file packaged in the “tar.gz” format. Let’s get into these possibilities:

If the tar.gz File Contains the Source Code

In most of the cases, the “tar.gz” file contains a source code. This source code needs to be dealt sequentially, i.e., build it for compilation, compile it, and then execute the installable files. Let’s go through the steps:

Note: As an example, we are using the source binaries (tar.gz file) of NodeJS.

Step 1: Acquire the Tool to Compile and Install the Package

The compilation and installation of the source code requires the compilation tool, i.e., make. It is recommended to Install the whole toolkit (a set of compilers including the make) using the command as per your distribution:

For Debian/Ubuntu Derivatives:

sudo apt install build-essential

For Fedora/RHEL Derivatives:

sudo dnf group install "Development Tools" "Development Libraries"

For Arch/Manjaro Derivatives:

sudo pacman -Sy base-devel

Step 2: Extract the “tar.gz” File

The “tar” utility with its flags “-xzf” extracts the files in a new directory:

tar -xzf <Path-of-the-tar.gz>

Navigate to the extracted directory as well.

Step 3: Build the Source Code

The configure script builds the source code for compilation. The script creates a Makefile which contains the instructions for compilation Run the below command in the extracted directory:

./configure

Step 4: Compile the Source Code

Now, compile the source code via the following command. The command reads the instructions written in the Makefile and creates an executable file/program for installation:

make -j 4

Note: The “-j num” parameter accelerates the compilation process by running the mentioned jobs (3,4,5) simultaneously.

Step 5: Install the Executable

The make command creates the executable that can be installed with the make install command:

sudo make install

You are good to go with the newly installed application.

Important: The above-mentioned commands/steps are the standard commands to install a package from the source. However, each source code packaged in the “tar.gz” may depend on various dependencies. The dependencies issues can be resolved by installing the required dependencies on your distribution.

If the tar.gz File Contains the AppImage

AppImage is rarely seen to be equipped with the tar.gz file. To install a package that has an AppImage compressed in tar.gz format, you need to follow a two-step method, as stated below:

Step 1: Extract the tar.gz File

Use the tar command with “xf” flag to extract the downloaded “tar.gz”:

tar -xf <path/to/tar.gz>

Navigate to the extracted folder using the cd command:

cd <Extracted Directory>

Step 2: Make the AppImage Executable/Execute the AppImage

Make the AppImage executable using the chmod command:

sudo chmod +x <Name of the AppImage>

Now, execute it:

./<AppImage>

That’s how you can execute the AppImage shipped in the form of tar.gz.

If the tar.gz File Contains the .deb or .rpm File

The tar.gz file may contain the distribution-specific packages. For instance, the “.deb” for the Debian/Ubuntu derivatives and the “.rpm” for the Fedora/RHEL derivatives. In such a case, the first step is the same for all methods, that is to extract the tar.gz file. The rest of the steps vary from distribution to distribution. Let’s discuss them:

Step 1: Extract the tar.gz File

Use the tar command with the xf flag to extract the tar.gz file and use the cd command to navigate to the extracted directory:

tar -xf <File-Name>

cd <Extracted-Directory>

Step 2: Install the Package

Now, trace the package type and install it using the respective command, as follows:

Package Type

 

Installation Command

 

“.deb”

 

sudo apt install <Path to Deb-Package>

 

“.rpm”

 

sudo dnf localinstall <Path to RPM-Package>

 

sudo yum localinstall <Path to RPM-Package>

 

sudo rpm -i <Path to RPM-Package>

How to Remove/Uninstall the Package Installed From tar.gz?

What if you want to remove the package installed from the tar.gz? In such a case, it depends on the package type that was extracted/installed from the tar.gz file. Let’s have a look at the possibilities:

If Installed From the Source

If the package you want to remove is installed from the source method, then you have to run the make uninstall command:

sudo make uninstall

How to Fix the Uninstall Target Not Found?

In a few cases, the make might not find the “uninstall” target. You won’t be able to uninstall with the above command. In such a scenario, you have to look for the files inside the possible executable locations, i.e., /usr.local/bin, /usr/local/libexec. If you are unable to find them, use the “which” or “whereis” command to get the exact path of the executable. Once found, you can remove them using the rm command.

If Installed From the AppImage

The AppImage method comes into action when you make that file executable. Thus, it can be uninstalled by removing the execution permission, as follows:

sudo chmod -x <Path-to-AppImage>

If Installed From the Other Methods (.deb or .rpm)

If you have installed the package using the distribution-specific package extension, then you need to follow the respective distribution’s uninstall command to remove the package. The possible methods are listed below:

Package Type

 

Removal/Uninstallation Method

 

.deb

 

sudo apt autoremove <Installed-Package-Name>

 

.rpm

 

sudo dnf autoremove <Installed-Package-Name>
Important: Ensure that you are using the correct package name. The package installed using this method must not be the same as that of the one in the file. (For instance, “balenaetcher_1.18-1.deb” installs the package with the balenaetcher name only.)

How to Install tar.bz2, tar.xz File on Ubuntu/Linux?

The tar.bz2 and tar.xz are the competitors of the “tar.gz”. The tar.xz executes slowly but has an excellent compression capability. Well. the process of installation of “tar.bz2” and “tar.xz” is the same as that of the “tar.gz”. Usually, all these two-step techniques are adopted/used for the source code files (where the installation depends on a large number of files).

The only difference might come at the time of extracting the files. You have to use the “j” option with the “tar” command to extract the files, as:

tar -xjf <tar.xz or tar.bz2 file>

Bottom Line

A tar.gz file does not always contain a specific package. Mostly it is equipped with the source code of that package as the source code-based installations have a large number of files. However, you may also get the AppImage, .deb, or .rpm files inside the tar.gz file. Thus, there is no specific installation method for the tar.gz files.

You need to extract and identify the file inside the tar.gz file and then use the relevant installation method discussed here.

Print Friendly, PDF & Email
Categories