Linux tar Command Not Found? Fix It on Your System
In this article
If Linux says tar: command not found, the tar program is missing or your shell cannot find it in the current PATH. Install the appropriate package for your distribution, or check whether the command is available at a location outside your PATH; then verify it with tar --version.
What the error means
tar is a standard command-line utility for creating and extracting archive files. It is not a shell keyword: the shell must locate an executable named tar to run it. The error usually means no matching executable is available in the directories listed in PATH. A mistyped command or a restricted container or minimal installation can produce the same result.
This is different from an error such as tar: archive.tar: Cannot open, which means the program ran but could not access a named file. Likewise, an “unrecognized option” message points to command syntax or version differences, not a missing installation.
Install tar with your distribution’s package manager
Package names and package managers vary. Use the command for the Linux distribution in question, and follow any prompts. Installing software generally requires administrator privileges, commonly provided with sudo:
- Debian or Ubuntu:
sudo apt update, thensudo apt install tar. - Fedora:
sudo dnf install tar. - RHEL, Rocky Linux, or AlmaLinux:
sudo dnf install tar. Older releases may useyum. - Arch Linux:
sudo pacman -S tar. - Alpine Linux:
sudo apk add tar. - openSUSE:
sudo zypper install tar.
These commands assume the system can reach its configured repositories and that you have permission to install packages. On a managed work machine, ask an administrator rather than trying to bypass access controls. Package commands may differ on older releases, so check the distribution’s documentation if the suggested command is unavailable.
Check whether tar is installed but not found
Before installing, check whether the executable is already visible to the shell. These commands work in common Bash-like shells:
command -v tarprints the path if the shell can locate it.type -a tarcan show how the shell resolves the name, including multiple matches.echo "$PATH"displays the directories searched for commands.
If command -v tar returns a path, try that executable directly, for example /usr/bin/tar --version if that is the path reported. If a known installation directory is missing from PATH, correct the shell or application environment rather than making a blind change to system-wide settings. A new terminal session may be needed after changing a profile or environment configuration.
If the command works in an interactive terminal but fails in a script, cron job, service, or application, compare the environments: those processes often receive a shorter or different PATH. Using the verified absolute path in a script can help, but make sure that path is correct on every system where the script will run.
Containers, minimal systems, and restricted environments
Container images, rescue environments, and minimal Linux installations may intentionally omit utilities that are commonly present on full desktop or server installations. Install tar in the image or environment using its own package manager. For Docker, for example, the correct installation command depends on the image’s base distribution; Debian-based and Alpine-based images do not use the same package manager.
Some environments are read-only, have no network access, or do not include a package manager. In those cases, you may need to rebuild the image with the package included, use an approved image that already contains it, or ask the administrator to provide the tool. Installing a package on the host does not automatically install it inside a container.
Verify the fix and use tar safely
After installation or a PATH correction, open a fresh shell if needed and run:
tar --versionto confirm the program runs.tar -tf archive.tarto list an archive’s contents without extracting them.tar -xf archive.tarto extract an archive into the current directory.
For a compressed archive, common examples include tar -xzf archive.tar.gz for gzip and tar -xJf archive.tar.xz for xz. Many current GNU tar versions detect compression when extracting, so tar -xf archive.tar.gz may also work; options and behavior can vary among tar implementations. To create a gzip-compressed archive, use tar -czf backup.tar.gz folder/.
Inspect archives from untrusted sources before extracting them, and extract them into a dedicated directory when possible. Archive entries can contain paths that target locations beyond the intended folder, and extraction can overwrite existing files. Listing the contents first helps you understand what will be written; do not extract an untrusted archive as root unless there is a clear, necessary reason.
Tar is not the same as a compression format
A common point of confusion is that a .tar file is an archive, while .gz and .xz refer to compression formats. Tar groups files and directories, preserving details such as names and, depending on options and permissions, file metadata. It does not necessarily compress the data. A file named backup.tar.gz is typically a tar archive compressed with gzip; tar can handle both parts when given the appropriate options.
Installing a separate tool such as gzip or xz may be necessary on a very minimal system if tar reports that a compression program is missing. That is a different problem from tar: command not found: first identify which program the error names, then install the corresponding package.
Frequently Asked Questions
How do I check whether tar is installed on Linux?
Run command -v tar or tar --version. If the first prints a path, the shell can find the command; if the second prints version information, tar is running.
What package contains tar on Ubuntu?
The package is named tar. Install it with sudo apt update followed by sudo apt install tar, assuming you have administrator privileges and access to the configured repositories.
Why does tar work in the terminal but not in a script?
The script may run with a different PATH or under a different user. Check its environment with echo "$PATH" in the relevant context, and consider using the confirmed absolute path to the executable.
Is tar installed by default on Linux?
Many general-purpose distributions include it, but minimal installations and container images may not. Availability depends on the distribution, image, and installation choices.
Can I use unzip instead of tar?
Only for formats it supports, such as ZIP files. unzip does not generally replace tar for .tar, .tar.gz, or .tar.xz archives; use a tool that supports the specific format.