Inside this guide

To back up your Termux home folder, archive your projects and configuration files, copy it off the phone, and test it before deleting anything. When you restore, unpack the archive into a new folder first. That lets you inspect your files before you merge them into a fresh Termux setup.

Use these steps from a regular Termux shell on Android. You'll need GNU tar, enough free space for the archive, and a trusted place outside the phone to keep a copy. If GNU tar is missing from your Termux session, install it through Termux's package manager.

Terminal
pkg install tar

What this backup includes

The home folder contains your projects, scripts and dotfiles, such as shell settings. Termux keeps the programs you install with its package manager in a separate location called the prefix. This guide archives the home folder only. Reinstall the tools you need on the new phone instead of copying the old package directory wholesale.

If you have Termux storage shortcuts, the archive skips the top-level storage folder. Back up any Android downloads, photos, or files saved through those links separately. If you saved real files directly inside the storage folder, those are excluded too.

A home archive can contain SSH keys, tokens and command history. Keep it private. If it contains secrets, use encrypted storage or encrypt the archive before moving it through a shared location.

Create and inspect the archive

Stop any active project jobs that are writing to your home folder. Then run the command below. It creates a new backup directory and archives the contents of your home folder, including hidden files.

Terminal
mkdir ~/termux-home-backup && tar --exclude='./termux-home-backup' --exclude='./termux-restore-check' --exclude='./storage' -czf ~/termux-home-backup/home.tar.gz -C ~ .

The command skips its own output directory and the restore test directory used below. If the directory already exists, mkdir fails and tar does not run. Preserve the previous backup before reusing the name. If tar reports an error, treat the resulting archive as incomplete.

List the saved files and check for a few important projects and dotfiles you expect to see.

Terminal
tar -tzf ~/termux-home-backup/home.tar.gz

Save a package inventory alongside the archive. Use it to identify the tools you need to reinstall.

Terminal
pkg list-installed > ~/termux-home-backup/packages.txt

Save a copy outside the phone

Keep both files somewhere you can reach if the phone is lost or reset. In an Android file manager that supports the system document picker, look for the Termux location to open its home folder. Copy the backup folder out using a transfer method you trust. If your setup already exposes Android shared storage, you can use it as a temporary transfer location for a backup that contains no secrets or has been encrypted. A backup stored only inside Termux can disappear when you uninstall the app or clear its data.

Test a restore in a separate folder

On the destination phone, install Termux and GNU tar. Then use the document picker or your trusted transfer method to place the backup folder in Termux home. You can also test the original archive on your current phone before making changes. Only unpack an archive you created or trust.

Terminal
mkdir ~/termux-restore-check && tar -xzf ~/termux-home-backup/home.tar.gz -C ~/termux-restore-check

This creates a new directory. If it already exists, use a fresh directory name in both places in the command. Open a few restored files, including a hidden configuration file if you backed one up. Reinstall needed packages using your inventory as a reference, then copy the projects and settings you need into place. Review old absolute paths and startup files before reusing them. Keep the original backup until the restored projects work.

Cover illustration generated with AI.

Prepared with AI-assisted research and writing using the sources below.

Sources

Termux project — File system layout

https://github.com/termux/termux-packages/wiki/Termux-file-system-layout

Termux tools — Package management, shared storage and backups

https://github.com/termux/termux-tools/blob/master/doc/termux.1.md.in

GNU tar manual — Creating, listing and extracting archives

https://www.gnu.org/software/tar/manual/tar.pdf