A tar.gz file in Linux must be extracted before you can run any of its contents. This guide shows you exactly how to run a tar gz file in linux, step by step. You will learn extraction, permissions, and execution without any confusion.
Many beginners think they can double-click a tar.gz file and run it. That is not how Linux works. You need to use the terminal for most tasks. But don’t worry, it is simpler than it sounds.
Think of a tar.gz file like a zip folder. It contains compressed files. You must unpack it first. Then you can run programs, scripts, or binaries inside.
How To Run A Tar Gz File In Linux
To run a tar.gz file, you need three main steps: extract the archive, navigate to the extracted folder, and execute the file. Each step uses simple commands. Let’s break it down.
What Is A Tar Gz File Exactly
A tar.gz file is two things combined. The “tar” part bundles files together. The “gz” part compresses them. Together, they save space and keep files organized.
You will see these files often for software downloads. Developers use them to distribute applications. They are common in open-source projects.
Prerequisites Before You Start
You need a Linux system with a terminal. Most distributions come with tar pre-installed. Check by typing tar --version in your terminal.
You also need basic file permissions. Your user account should have read and write access to the download directory. If not, use sudo when needed.
Step-By-Step Extraction Process
Extraction is the first real step. You cannot run anything until the files are unpacked. Use the terminal for best results.
Open The Terminal
Press Ctrl+Alt+T to open a terminal window. Or search for “Terminal” in your applications menu. This is where you will type all commands.
Navigate To The File Location
Use the cd command to go to the folder containing your tar.gz file. For example, if it is in Downloads, type:
cd ~/Downloads
Check the file is there with ls. You should see your file listed.
Extract The Archive
Run the extraction command. The most common one is:
tar -xzf filename.tar.gz
Breakdown of the flags:
-xmeans extract-zmeans decompress gzip-fmeans use the file name that follows
Replace “filename.tar.gz” with your actual file name. Press Enter and wait for it to finish.
If you want to see the progress, add the -v flag for verbose output:
tar -xzvf filename.tar.gz
This shows each file as it extracts. It helps you see what is happening.
Check The Extracted Folder
After extraction, run ls again. You should see a new folder or files. The folder name often matches the archive name without the extension.
For example, if you extracted “myapp.tar.gz”, you might see a folder called “myapp”.
How To Run The Extracted File
Now you have the files. But how do you run them? It depends on what type of file is inside.
Identify The Executable File
First, navigate into the extracted folder:
cd myapp
List the contents with ls -l. Look for files with execute permissions (x in the permissions column). Common executable names include:
- ./program
- ./app
- ./run.sh
- ./install.sh
If you see a file ending in .sh, it is a shell script. If it has no extension, it is likely a binary executable.
Make The File Executable
Sometimes the file does not have execute permissions. You can add them with:
chmod +x filename
Replace “filename” with the actual file name. This gives you permission to run it.
Run The File
To run a file in the current directory, use ./ before the name. For example:
./program
If it is a shell script, you can also run it with:
bash run.sh
Press Enter. The program should start. If it fails, check the error message. Common issues include missing dependencies or wrong architecture.
Common Scenarios And Solutions
Sometimes things do not work as expected. Here are frequent problems and fixes.
Permission Denied Error
You see “Permission denied” when trying to run a file. This means the file is not executable. Use chmod +x as shown above.
If that does not work, you might need to run with sudo:
sudo ./program
Be careful with sudo. Only use it if you trust the file.
Command Not Found
If you type the command and get “command not found”, you are likely in the wrong directory. Use pwd to check your current path. Then navigate correctly.
Missing Library Errors
Some programs need libraries. If you see errors about missing .so files, install the required libraries. Use your package manager, like apt or yum.
Architecture Mismatch
If you downloaded a 64-bit program on a 32-bit system, it will not run. Check your system architecture with uname -m. Download the correct version.
Advanced Extraction Options
Sometimes you need more control over extraction. Here are useful variations.
Extract To A Specific Directory
Use the -C flag to extract to a different folder:
tar -xzf filename.tar.gz -C /target/directory
This keeps your current folder clean.
List Contents Without Extracting
To see what is inside without extracting, use:
tar -tzf filename.tar.gz
This lists all files. Helpful for checking before extraction.
Extract Only Specific Files
If you need only one file from the archive, specify it:
tar -xzf filename.tar.gz path/to/file
This extracts just that file.
Running Different File Types
Not all tar.gz files contain the same type of executable. Here is how to handle common ones.
Binary Executables
These are compiled programs. They usually have no extension. Just make them executable and run with ./.
Shell Scripts
Scripts end in .sh. Run them with bash script.sh or make them executable and use ./script.sh.
Python Scripts
If the file ends in .py, you need Python installed. Run with:
python3 script.py
Java Applications
Java programs often come as .jar files. Run them with:
java -jar app.jar
Make sure Java is installed.
Installation Scripts
Some tar.gz files contain an installer. Look for install.sh or configure. Run the installer first.
Using Graphical Tools
If you prefer not to use the terminal, you can use GUI tools. Most Linux desktops have archive managers.
Extract With File Manager
Right-click the tar.gz file. Select “Extract Here” or “Extract to…”. This unpacks the files.
Then open the folder and double-click the executable. If it does not run, you may need to set permissions via the file properties.
Using Archive Manager
Open the archive manager app. Drag your tar.gz file into it. Click “Extract”. Choose a location.
This method is slower but works for beginners.
Safety Tips When Running Tar Gz Files
Not all tar.gz files are safe. Follow these precautions.
Check The Source
Only download from trusted websites. Official project pages are best. Avoid random links.
Scan For Malware
Use clamscan or other antivirus tools. Scan the file before extraction:
clamscan filename.tar.gz
Inspect The Contents
List the files before extracting. Look for suspicious names. If you see something like install.sh in a random folder, be cautious.
Run In A Sandbox
If you are unsure, run the program in a virtual machine or container. This protects your main system.
Automating The Process
If you often download tar.gz files, you can automate extraction and running.
Create A Shell Script
Write a script that extracts and runs a file. For example:
#!/bin/bash
tar -xzf "$1"
cd "$(basename "$1" .tar.gz)"
./program
Save it as run-tar.sh. Make it executable. Then run it with the tar.gz file as an argument.
Use Aliases
Add an alias to your .bashrc file:
alias untar='tar -xzf'
Now you can just type untar file.tar.gz.
Troubleshooting Common Issues
Even experienced users hit problems. Here are more solutions.
Corrupted Archive
If extraction fails with an error, the file might be corrupted. Re-download it. Check the file size matches the source.
Disk Space Full
Extraction needs free space. Use df -h to check disk usage. Free up space if needed.
Wrong File Format
Some files have multiple extensions like .tar.bz2. Use the correct command:
- For .tar.bz2:
tar -xjf file.tar.bz2 - For .tar.xz:
tar -xJf file.tar.xz
File Name With Spaces
If the file name has spaces, enclose it in quotes:
tar -xzf "my file.tar.gz"
Real-World Example
Let’s run through a complete example. Suppose you downloaded “node_exporter-1.5.0.linux-amd64.tar.gz”.
- Open terminal: Ctrl+Alt+T
- Navigate:
cd ~/Downloads - Extract:
tar -xzf node_exporter-1.5.0.linux-amd64.tar.gz - List files:
ls(you see a new folder) - Enter folder:
cd node_exporter-1.5.0.linux-amd64 - Check permissions:
ls -l(see node_exporter file) - Make executable:
chmod +x node_exporter - Run:
./node_exporter
The program starts. You can stop it with Ctrl+C.
Frequently Asked Questions
How do I run a tar.gz file without terminal?
Right-click the file and extract it with your archive manager. Then double-click the executable inside. If it does not run, set permissions via file properties.
Can I run a tar.gz file directly without extracting?
No. You must extract it first. The tar.gz format is compressed and bundled. You cannot execute it directly.
What is the difference between tar.gz and zip?
Tar.gz is common on Linux. Zip is more universal. Both compress files. Tar.gz preserves permissions better on Linux systems.
Why do I get “command not found” when running a tar.gz file?
You are likely in the wrong directory or the file is not executable. Use cd to navigate to the extracted folder. Then use ./ before the file name.
How do I install software from a tar.gz file?
Extract the archive. Look for an install script like install.sh or configure. Run it. Some programs just need to be copied to a directory in your PATH.
Final Thoughts
Running a tar.gz file in Linux is straightforward once you understand the steps. Extract first, then execute. Use the terminal for control, or GUI for simplicity.
Always check the source of your files. Keep your system secure. With practice, you will handle tar.gz files without thinking.
Now you know how to run a tar gz file in linux. Try it with a sample file. You will see how easy it realy is.