How to Install a Tar.gz File in Ubuntu: A Complete Guide
If you've spent any time working in Ubuntu — whether setting up a development environment, deploying a web app, or installing software not available through the package manager — you've almost certainly encountered a .tar.gz file. These compressed archives are common in the Linux world, but the installation process isn't always obvious, especially if you're coming from Windows or macOS.
Here's exactly how it works, and what to watch for along the way.
What Is a Tar.gz File?
A .tar.gz file is a compressed archive. The name comes from two layered operations:
- tar (Tape Archive) bundles multiple files and directories into a single file
- gz (Gzip) compresses that bundle to reduce file size
Together, they're sometimes called a tarball. On Linux systems, tarballs are a standard way to distribute source code, precompiled binaries, and application packages — similar to how .zip files work on Windows.
Importantly, a .tar.gz file is not an installer in the traditional sense. What's inside determines how you proceed after extracting it.
Step 1: Extract the Tar.gz File
Open a terminal and navigate to the directory containing the file, then run:
tar -xvzf filename.tar.gz Breaking down the flags:
| Flag | Meaning |
|---|---|
-x | Extract files |
-v | Verbose — shows files as they extract |
-z | Decompress using Gzip |
-f | Specifies the filename follows |
To extract into a specific directory, add the -C flag:
tar -xvzf filename.tar.gz -C /path/to/destination After extraction, you'll have a new folder containing the contents of the archive.
Step 2: Identify What's Inside 🔍
This is where many users get stuck. The contents of the extracted folder determine your next move entirely. Common scenarios include:
Pre-compiled binaries — Ready-to-run executable files. No compilation needed. You just run them or move them to a standard location.
Source code — Raw code that must be compiled before it can run. Usually contains a Makefile and a configure script.
Scripts or assets — Plain files like shell scripts, configuration files, or web assets that just need to be placed in the right directory.
Look for a README or INSTALL file first. Most well-maintained packages include one, and it will tell you exactly what the developer intended.
Step 3A: Running a Pre-compiled Binary
If the archive contains a binary (an executable file), navigate into the extracted folder:
cd extracted-folder-name ./binary-name The ./ tells the terminal to run the file in the current directory. You may need to make it executable first:
chmod +x binary-name To make the binary accessible system-wide (so you can run it from any directory), move it to /usr/local/bin:
sudo mv binary-name /usr/local/bin/ Step 3B: Compiling from Source
Source code installation is the most involved path. It typically follows the classic configure → make → make install sequence.
cd extracted-folder-name ./configure make sudo make install What each step does:
./configure— Checks your system for required dependencies and generates a Makefile tailored to your setupmake— Compiles the source code into an executable binarysudo make install— Copies the compiled files to the appropriate system directories
If ./configure fails, it usually means a required dependency is missing. The error message will name it. Install it via apt and try again:
sudo apt install missing-package-name Some modern projects use CMake or Meson instead of Autotools. In those cases, the README will outline a different build sequence — but the general concept is the same.
Step 3C: Shell Scripts or Web Assets
For tarballs containing scripts or static files, installation is manual. You copy files to wherever your setup expects them — a web root directory like /var/www/html/, a config directory, or a custom application folder.
Always check file permissions after copying. Web servers and other services often require specific ownership settings.
System-Level Variables That Affect the Process ⚙️
The same .tar.gz file can behave differently depending on your environment:
- Ubuntu version — Dependencies available via
aptvary between LTS and non-LTS releases. A package that compiles cleanly on Ubuntu 22.04 may fail on 20.04 due to older library versions. - System architecture — Pre-compiled binaries are architecture-specific. An
x86_64binary won't run on an ARM-based system (like a Raspberry Pi or Apple Silicon running Ubuntu). Always verify the binary matches your CPU architecture. - Installed development tools — Source compilation requires
build-essential(which includesgcc,g++, andmake). A minimal Ubuntu install may not have these. Install them withsudo apt install build-essential. - Permissions and user context — Installing system-wide requires
sudo. Installing to a user's home directory does not. Mismatched permissions are a common source of errors. - Existing package conflicts — If a different version of the same software is already installed via
apt, manually installing from a tarball can create conflicts.
When a Package Manager Is the Better Path
Ubuntu's apt package manager handles dependencies, updates, and uninstallation cleanly. If the software you need is available via apt, a PPA, or Snap, that route is generally more straightforward to maintain.
Tarballs are most appropriate when:
- The software isn't available in any Ubuntu repository
- You need a specific version not yet packaged
- You're working with proprietary or internal tools
- You need to install to a non-standard location
The right approach depends heavily on your project requirements, your comfort level with the command line, and how you plan to manage updates going forward — factors only you can weigh against your specific setup.