Tar gz archives bundle multiple files together while compressing them for efficient distribution on Linux. If you are wondering how to install a tar gz file in linux, you are not alone—many users encounter these compressed packages when downloading software from source or third-party sites. This guide walks you through the entire process, from extraction to installation, with clear steps and practical tips.
Tar gz files, also known as tarballs, are common in the Linux ecosystem. They combine the tar archiving format with gzip compression, making them ideal for sharing code, applications, or configuration files. Unlike package managers like apt or yum, installing from a tar gz requires manual steps, but it gives you more control over the software.
Understanding Tar Gz Files
A tar gz file ends with the extension .tar.gz or sometimes .tgz. It contains one or more files compressed together. To use the software inside, you must first extract the archive, then often compile or run the installer.
These files are not always pre-compiled binaries. Many contain source code that needs compilation, while others include ready-to-run executables. Knowing which type you have saves time and frustration.
Why Use Tar Gz Archives
Developers prefer tar gz for distributing software because it preserves file permissions and directory structures. It also works across all Linux distributions without dependency on package managers.
For users, tar gz files offer access to newer versions of software not yet in official repositories. However, they require more effort to install, making this skill essential for any Linux user.
How To Install A Tar Gz File In Linux
Now we get to the core of the article. The exact process depends on whether the tar gz contains source code or pre-compiled binaries. Below are the general steps, followed by specific methods for each scenario.
Step 1: Download The Tar Gz File
First, download the file from a trusted source. Use your browser or the wget command in the terminal. For example:
wget https://example.com/software.tar.gz
Save the file to a directory you can easily access, like your Downloads folder or a dedicated directory in your home folder.
Step 2: Extract The Archive
Use the tar command to extract the contents. Open a terminal and navigate to the directory containing the file:
cd ~/Downloads
Then extract with:
tar -xzf software.tar.gz
Here is what the flags mean:
- -x: Extract files
- -z: Decompress with gzip
- -f: Specify the filename
After extraction, you will see a new directory (usually named after the software). List the contents with ls to verify.
Step 3: Check The Contents
Navigate into the extracted directory:
cd software
Look for key files like README, INSTALL, configure, Makefile, or a binary executable. The README file often contains installation instructions specific to that package.
If you see a file named configure, it is likely source code that needs compilation. If you see a binary file (no extension), it may be ready to run.
Step 4: Install From Source Code
For source code tarballs, follow the classic three-step process: configure, make, make install. This requires build tools like gcc and make. Install them if needed:
sudo apt update && sudo apt install build-essential
Then run:
./configure– Checks dependencies and prepares the build.make– Compiles the source code.sudo make install– Copies the compiled files to system directories.
If configure fails, read the error messages. You may need to install missing libraries. For example, if it complains about libssl, install libssl-dev.
Step 5: Install Pre-Compiled Binaries
Some tar gz files contain pre-compiled binaries. In this case, you can often run the software directly from the extracted folder. Look for an executable file (check with ls -l for execute permissions).
To make it system-wide, copy the binary to /usr/local/bin:
sudo cp binary-name /usr/local/bin/
Alternatively, add the extracted directory to your PATH environment variable. Edit your ~/.bashrc file and add:
export PATH=$PATH:/path/to/extracted/directory
Then reload with source ~/.bashrc.
Step 6: Verify The Installation
Test that the software runs correctly. For a binary, simply type its name in the terminal. For compiled software, check with a version flag:
software-name --version
If you get an error, double-check permissions and paths. You may need to run sudo ldconfig if shared libraries are involved.
Common Issues And Solutions
Installing tar gz files is not always smooth. Here are frequent problems and how to fix them.
Missing Dependencies
During configure or make, you might see errors about missing headers or libraries. Use your package manager to install the required -dev packages. For example, on Debian/Ubuntu:
sudo apt install libfoo-dev
Search for the missing package name using apt search or check the error message carefully.
Permission Denied
If you cannot run the extracted binary, it may lack execute permissions. Fix with:
chmod +x binary-name
For system-wide installation, you need sudo for copying to protected directories.
Compilation Errors
Sometimes the source code is outdated or incompatible with your kernel. Check the software’s documentation or forum for patches. Alternatively, look for a pre-compiled version or a PPA.
Path Not Found
If you moved the extracted folder, update any symlinks or PATH entries. Keep the folder in a stable location like /opt.
Alternative Methods For Installation
Besides the manual approach, there are tools that simplify tar gz installation. These are not always reliable but can save time.
Using Checkinstall
Checkinstall creates a .deb or .rpm package from the compiled source, making removal easier. Install checkinstall first:
sudo apt install checkinstall
Then, instead of sudo make install, run:
sudo checkinstall
It will prompt for package details and create an installable package.
Using Stow Or GNU Stow
Stow manages symlinks for manually installed software. Install stow, then after make install, use:
sudo stow -t /usr/local software-name
This keeps the original files in one directory and links them to system paths.
Removing Software Installed From Tar Gz
Uninstalling is trickier than with package managers. If you kept the source directory, you can often run:
sudo make uninstall
If the Makefile does not support uninstall, you must manually delete the files. Check the install_manifest.txt file if it exists, or use checkinstall to create a package for easy removal.
For binaries copied to /usr/local/bin, simply delete them:
sudo rm /usr/local/bin/binary-name
Frequently Asked Questions
What Is The Difference Between Tar Gz And Zip?
Tar gz is native to Linux and preserves Unix file permissions and metadata. Zip is cross-platform but lacks some Unix-specific features. Tar gz is more common for source code distribution.
Can I Install A Tar Gz File Without Root Access?
Yes, you can extract and run binaries from your home directory. For source code, use the –prefix option with configure to install to a local directory like ~/.local.
How Do I Know If A Tar Gz Contains Source Or Binaries?
Look for files like configure, Makefile, or .c files—these indicate source code. If you see only executables and shared libraries (.so files), it is likely pre-compiled.
Why Does Make Install Fail With Permission Errors?
You need sudo for installing to system directories like /usr/local. Alternatively, change the install prefix to a user-writable location.
Is It Safe To Install Software From Tar Gz Files?
Only if you trust the source. Since tar gz files bypass package manager security checks, verify the download with checksums or GPG signatures when available.
Best Practices For Managing Tar Gz Installations
Keep a log of manually installed software. Create a directory like /opt for third-party applications. Document the installation steps and any dependencies you added.
Use version control for configuration files. If you compile software, keep the source directory in case you need to reinstall or uninstall later.
Regularly update manually installed software by downloading new versions and repeating the process. Unlike packages from repos, these do not update automatically.
Consider using containerization tools like AppImage or Flatpak for easier management. They bundle dependencies and do not require compilation.
Conclusion
Learning how to install a tar gz file in linux is a valuable skill that expands your software options beyond package managers. While the process involves several steps—downloading, extracting, compiling or copying, and verifying—it becomes straightforward with practice. Always check the included documentation, handle dependencies carefully, and consider using tools like checkinstall for cleaner management. With these steps, you can confidently install any tar gz archive on your Linux system.
Remember to keep your system secure by only installing from trusted sources. If you encounter errors, read them carefully—they often point directly to the solution. Over time, you will develop a workflow that makes tar gz installations quick and painless.