Rust target Folder Is Huge: Is It Safe to Delete?

Yes, but read this firstDiskmack safety tier: Caution
**/target

Yes, you can delete a Rust project's target folder, with one catch: the next cargo build recompiles everything from scratch. You lose no source code and no downloaded crates, only build time. If the project is one you no longer touch, deleting its target folder is one of the easiest multi-gigabyte wins on a developer Mac.

What it is

The target folder is Cargo's build directory. It sits next to Cargo.toml in every Rust project and holds everything the compiler produces: your compiled binaries, compiled copies of every dependency, incremental compilation caches, build script output, and separate copies of all of that for debug and release builds. None of it is source code. Your code lives in src, and the crate sources you downloaded live in ~/.cargo/registry, shared across all projects.

It gets big because Rust compiles every dependency from source, per project, and Cargo almost never throws anything away. Switch between debug and release and you store both. Update your toolchain or toggle a feature flag and old artifacts stay behind next to the new ones. A small CLI project's target folder can sit at a few hundred MB; a workspace with heavy dependencies routinely reaches several gigabytes, and long-lived projects can climb well past 10 GB. If you have a projects folder full of old Rust experiments, the target folders in it may quietly be the largest thing you own.

Is it safe to delete?

Deleting target destroys nothing permanent. Your code, Cargo.toml, and Cargo.lock are untouched, and the crate sources stay cached in ~/.cargo, so a rebuild needs no network at all. The cost is purely time: the next cargo build starts cold and recompiles every dependency, which can take a few minutes on a small project and considerably longer on a big workspace. That is the whole trade.

Two things earn it the caution label. First, if you delete target on a project you're actively working on, you pay that full rebuild today, and tools like rust-analyzer will kick one off the moment you reopen the editor. Second, target is not a Rust-only name: Maven uses a target folder for Java build output too, and other tools may as well. Check that Cargo.toml sits next to it before assuming it belongs to Rust. Either way it's build output, but it's worth knowing whose. Diskmack finds target folders across all your projects and moves them to the Trash rather than deleting them outright.

How to check its size

In Finder: In Finder, choose Go > Go to Folder (Cmd+Shift+G) and enter your project's path, for example ~/Projects/my-app. Click the target folder once, then press Cmd+I (File > Get Info) and wait a moment while Finder tallies the size.

In Terminal:

du -sh ~/Projects/my-app/target

Replace ~/Projects/my-app with your project's actual path; ~ stands for your home folder. If the path has spaces, quote everything after the ~, like du -sh ~/"My Projects/my-app/target". To compare several projects at once, run du -sh ~/Projects/*/target and read the list.

How to clean it

  1. Confirm it's a Rust project: the folder containing target should also contain a file named Cargo.toml.
  2. Stop anything that might be building: close the project in your editor and stop any running cargo watch.
  3. In Finder, open the project folder and drag target to the Trash.
  4. Empty the Trash when you're sure. The space isn't reclaimed until you do.
  5. Repeat for any old projects you no longer build. Abandoned projects are where the real gigabytes hide.

If you're comfortable in Terminal, cd into the project and run cargo clean instead. It removes the target folder and nothing else.

Will it come back?

Yes, immediately and by design. The next cargo build, cargo run, or cargo test recreates target and fills it back up, and just opening the project in an editor running rust-analyzer usually triggers a build too. The first build after cleaning is the slow one; after that, incremental compilation keeps things quick while the folder resumes growing. On projects you've genuinely abandoned, it stays gone, which is why old projects are the best place to clean.

Common questions

Why is my Rust target folder so huge?

Rust compiles every dependency from source and stores the results per project, in separate debug and release variants, plus incremental caches. Cargo doesn't evict stale artifacts, so toolchain updates and feature changes pile new output on top of old. Multi-gigabyte target folders are normal, not a sign anything is wrong.

Will deleting target break my project?

No. Everything in target is generated from your source code and Cargo.lock. Delete it and the next cargo build recreates it. The only thing you lose is the time the rebuild takes.

Do my crates re-download after I delete target?

No. Downloaded crate sources live in ~/.cargo/registry, which is a separate shared cache. A rebuild after deleting target recompiles locally and needs no network connection.

Can I stop target folders from taking over my disk?

Mostly by habit: run cargo clean on projects when you shelve them. You can also set the CARGO_TARGET_DIR environment variable to point every project at one shared build directory, which makes the disk usage easier to see and clean in one place.

Related folders