How to Clear Cache and Temporary Files on macOS for Developers
Our guides are based on hands-on testing and verified sources. Each article is reviewed for accuracy and updated regularly to ensure current, reliable information.Read our editorial policy.
Developers can clear cache and temporary files on macOS by removing unused package downloads, browser data, build artifacts, and Docker resources. The safest approach is to check what consumes storage first, then use each development tool’s built-in cleanup options.
A developer’s Mac constantly generates files that aren’t part of the source code. Package managers download dependencies, browsers cache website resources, IDEs create search indexes, and development frameworks generate temporary build outputs.
Over time, these files can consume several gigabytes of storage, particularly when you’re working across multiple projects.
However, not everything labeled as a cache is unnecessary. Some cached data makes applications faster, while other directories contain important project information that shouldn’t be removed.
This guide explains how to safely clean up cache and temporary files on macOS without accidentally deleting source code, databases, credentials, or files needed for future builds.
What Cache and Temporary Files Can You Safely Delete on macOS?
Before cleaning anything, understand the difference between cached files, generated build artifacts, and persistent project data.
A cache stores information an application can reuse instead of downloading or processing it again. Build artifacts are generated during compilation or packaging. Persistent data includes files that applications need to preserve between sessions.
These categories have different cleanup risks.
| File Type | Examples | Cleanup Guidance |
|---|---|---|
| Package caches | npm downloads, Homebrew cached packages | Use supported package manager commands |
| Browser cache | Cached images, scripts, and website resources | Remove selectively when troubleshooting or reclaiming storage |
| Build artifacts | dist, build, .next |
Usually removable when the project can be rebuilt |
| IDE indexes | Generated code indexes and development metadata | Clear selectively when troubleshooting |
| Xcode DerivedData | Compiled resources and indexes | Generally rebuildable, but removal may trigger lengthy rebuilding |
| Docker build cache | Cached build layers and related resources | Reclaimable, but subsequent builds may take longer |
| Persistent data | Databases, Docker volumes, project configuration | Inspect carefully and back up important files |
Important: Never assume a file is safe to delete simply because it’s large, old, or located inside a development directory.
Check Your Mac’s Storage Before Cleaning
Start with the storage management features built into macOS.
On macOS Ventura or later:
- Open the Apple menu and select System Settings.
- Choose General from the sidebar.
- Click Storage.
- Review the available storage categories and recommendations.
- Inspect large files, unused applications, and downloads before removing anything.
On older macOS versions, storage information is available through About This Mac > Storage.
Apple’s storage management guide explains how to identify unnecessary files and reclaim storage using built-in features.
Check Available Disk Space Using Terminal
Developers who prefer the command line can check the filesystem containing their home directory:
df -h "$HOME"This displays filesystem capacity, used space, and available space in a human-readable format.
To inspect common development directories, run:
du -sh "$HOME/.npm" "$HOME/Library/Developer/Xcode/DerivedData" 2>/dev/nullThe du command estimates how much storage the specified directories consume. The error redirection hides messages if a directory doesn’t exist or cannot be inspected.
Both commands are read-only. They do not remove files.
Should You Use a Mac Cleanup Utility?
Manual cleanup provides more control, but reviewing multiple applications and directories can become time-consuming.
Third-party maintenance utilities can simplify general cache management by scanning for temporary files and presenting cleanup options in one interface.
For example, MacPaw explains how to clear cache using CleanMyMac, including options for locating and reviewing cached files before removal.
Such tools may be convenient for general maintenance. However, developers should inspect what a cleaner proposes to remove, especially when working with project directories, development tools, and application data.
For package managers, IDEs, and container platforms, built-in cleanup commands are often more precise.
Step 1: Clean Package Manager Caches
Package managers simplify software development by downloading dependencies and managing installed packages.
However, repeated installations and updates can leave cached downloads and older package versions behind.
Developers using Homebrew, npm, Yarn, and Composer may accumulate considerable package-related data over time.
These caches aren’t necessarily useless. They can speed up future installations and reduce repeated downloads.
Clean them when storage usage justifies it, rather than automatically deleting everything on a fixed schedule.
Clean Homebrew’s Cache
Homebrew can retain downloaded packages and older installed versions.
First, preview what Homebrew would remove:
brew cleanup -nThe -n option performs a dry run. It displays eligible cleanup candidates without deleting them.
If the results look appropriate, run:
brew cleanupThis removes eligible outdated downloads and old package versions according to Homebrew’s cleanup rules.
Review the official Homebrew manual for additional cleanup options.
Inspect and Clean npm Cache
npm stores downloaded package data locally to make future installations more efficient.
On macOS, the default cache is usually located inside ~/.npm.
First, check the configured location:
npm config get cacheThen verify the cache:
npm cache verifyThis command checks cache integrity and performs maintenance, including garbage collection of unnecessary cached data.
npm’s cache is designed to verify package integrity and recover from corrupted entries. Routine manual clearing is generally unnecessary.
If you’ve confirmed that the cache is unusually large and want to remove its contents, you can run:
npm cache clean --forceWarning: This removes npm’s cached package data. Future installations may need to download packages again, and offline installations may no longer have access to previously cached packages.
See the official npm cache documentation for the behavior of these commands.
If you’re new to managing JavaScript dependencies, the explanation of npm packages and dependencies covers how package manifests, lockfiles, and installed modules work together.
Review Yarn and Composer Caches
Yarn and Composer also cache downloaded dependencies.
However, cache locations and cleanup commands differ between versions, particularly between Yarn Classic and modern Yarn releases.
Check the documentation for your installed version instead of manually deleting unknown cache directories.
If your workflow depends on offline installs or a reproducible build environment, consider how removing cached dependencies may affect future installations.
Step 2: Clear Browser Cache and Website Data
Browsers store temporary files to reduce repeated downloads and improve page loading.
These files include images, stylesheets, JavaScript resources, and other website assets.
For web developers, cached resources can sometimes complicate testing. A browser may continue displaying an older version of a resource after a code change or deployment.
Clearing the relevant cache can help determine whether stale browser data is causing the problem.
Clear Website Data in Safari
To remove stored data for a specific website:
- Open Safari.
- Choose Safari > Settings.
- Select Privacy.
- Click Manage Website Data.
- Find and select the affected website.
- Click Remove.
This removes stored website data, which may include cookies and other site information. It can sign you out or reset website preferences.
If you only need to clear Safari’s cached resources, use its developer features:
- Open Safari > Settings > Advanced.
- Enable the option to show features for web developers.
- Open the Develop menu.
- Select Empty Caches, if available in your Safari version.
Menu wording may vary between Safari versions. Apple’s Safari website data guide explains the available options.
Clear Cached Files in Google Chrome
For Chrome:
- Open Chrome.
- Go to Settings > Privacy and security.
- Select Delete browsing data.
- Choose an appropriate time range.
- Select Cached images and files.
- Confirm the deletion.
If your goal is only to refresh cached resources, avoid deleting cookies or other website data unnecessarily.
For development testing, Chrome DevTools also provides an option to disable caching temporarily while DevTools remains open.
Remember: Clearing browser cache doesn’t guarantee faster browsing. The browser may need to download resources again on subsequent visits.
Step 3: Remove Old Build Artifacts
Build artifacts are another common source of unnecessary storage in development environments.
Frameworks and compilers generate files for production builds, previews, development servers, and intermediate processing.
Examples include:
distdirectories generated by JavaScript build tools.builddirectories containing compiled output..nextdirectories generated by Next.js.- Compiled binaries and intermediate build files.
- Old release packages and archived application builds.
Many of these files can be regenerated from the source project.
Inspect Project Directories Before Removing Build Files
Open an older project in Finder and review its generated directories.
Before deleting a folder, confirm that:
- It contains generated output rather than original source code.
- The project can be rebuilt from the remaining files.
- Important release files have been preserved.
- The directory doesn’t contain manually added assets or configuration.
- No active development process depends on the generated files.
For example, a Next.js project’s .next directory normally contains generated build and development output.
Next.js can recreate the directory when you run the development server or build the project again.
However, removing it while a development or production process is running can interrupt the application until the required files are regenerated.
Can You Delete node_modules?
JavaScript projects can accumulate large node_modules directories.
These contain installed dependencies rather than ordinary temporary cache files.
For an inactive project, removing the dependency directory may reclaim storage if the packages can be restored later.
Before doing so, preserve the project’s package.json and compatible lockfile.
For an npm project with a valid package-lock.json or npm-shrinkwrap.json, dependencies can usually be reinstalled with:
npm ciRun this command from the project directory.
Important: The npm ci command performs a clean dependency installation. If node_modules already exists, npm removes it before installing dependencies. The command also requires a compatible lockfile and fails if the dependency manifest and lockfile disagree.
Removing dependency directories can be inconvenient when a project relies on unavailable packages, custom local modifications, or private registry access.
Preserve your project files and important configuration before performing cleanup.
Step 4: Clean IDE, Xcode, and Docker Storage
IDEs and container platforms can generate substantial local data, including indexes, compiler outputs, simulator files, Docker images, and build caches.
Some resources are disposable. Others support active projects or contain persistent information.
Inspect them before making changes.
Manage IDE Caches Carefully
Integrated development environments create indexes to support code completion, navigation, inspections, and other development features.
These indexes can consume storage, but they also reduce the work required to analyze a project.
Clearing healthy IDE indexes on a fixed schedule is generally unnecessary.
If you’re using a JetBrains IDE and experience indexing problems, start with its built-in repair workflow.
In IntelliJ IDEA, for example, open File > Cache Recovery > Repair IDE.
The repair process provides targeted recovery steps before broader cache invalidation.
See the official JetBrains Repair IDE guide for instructions.
For other editors, consult their supported cache management procedures rather than deleting unknown application support directories.
Remove Unnecessary Xcode DerivedData
Xcode creates generated build products and indexing data, particularly when you’re working on multiple iOS or macOS projects.
Its DerivedData directory is commonly located at:
~/Library/Developer/Xcode/DerivedDataTo inspect it:
- Close active Xcode builds.
- Open Finder.
- Choose Go > Go to Folder.
- Enter the DerivedData path.
- Review folders associated with inactive projects.
Xcode can generally regenerate DerivedData during subsequent builds.
However, removing it may trigger lengthy rebuilding and reindexing.
Delete only generated data you no longer need, and avoid making changes while builds are running.
Review Xcode archives separately. They may contain application binaries, debugging symbols, and release information needed for distribution or troubleshooting.
Archives should not automatically be treated as disposable caches.
Inspect Docker Storage Before Cleanup
Docker can occupy significant disk space through container images, stopped containers, volumes, and build caches.
These resources serve different purposes, so inspect their storage usage before removing anything.
Start with:
docker system df -vThis command displays detailed Docker disk usage, including images, containers, and volumes.
If you’re unfamiliar with the relationship between images, containers, and persistent data, the explanation of Docker containers provides useful background.
Check Docker Desktop’s Disk Image on macOS
Docker Desktop on macOS stores Linux container data inside a virtual disk image rather than directly managing every container file through the macOS filesystem.
To inspect its storage usage:
- Open Docker Desktop.
- Go to Settings.
- Open Resources > Advanced.
- Review the disk image’s configured size limit and actual space usage.
The maximum disk image size is not necessarily the amount of physical storage currently consumed.
Some macOS storage tools may report the virtual disk’s maximum size rather than its actual usage.
Removing unused Docker objects can free space inside the virtual disk. However, the reclaimed space may not immediately appear as available space in macOS storage reports.
Docker explains this distinction in its Docker Desktop for Mac FAQ.
Warning: Do not manually move Docker’s disk image in Finder or reduce its configured disk limit without reviewing Docker’s instructions. Certain disk-size changes can recreate or delete the disk image, resulting in loss of local Docker data.
Remove Unused Docker Build Cache
If Docker’s build cache is consuming unnecessary storage, use:
docker builder pruneThis prompts for confirmation before removing eligible unused build cache.
Future builds may take longer because Docker must recreate deleted cached layers.
For broader cleanup, Docker provides:
docker system pruneBy default, this removes eligible stopped containers, unused networks, dangling images, and unused build cache.
Docker displays a confirmation prompt describing the resources being removed.
Warning: Review the list carefully before confirming. Removed containers, images, and cached layers may need to be recreated or downloaded.
Standard docker system prune does not remove Docker volumes.
Volumes require particular care because they can contain persistent development data, including PostgreSQL, MySQL, or other application databases.
Avoid using aggressive pruning options without verifying which resources will be removed and whether important data has been backed up.
Read Docker’s official pruning documentation for the behavior of each command.
Docker Disk Usage and RAM Usage Are Different Problems
Old images and build caches primarily consume disk space.
High memory usage generally relates to running workloads or resources allocated to Docker Desktop’s virtual machine.
Deleting unused images does not necessarily reduce the RAM used by active containers.
If Docker is consuming too much memory, inspect running containers and review Docker Desktop’s memory settings separately.
Common macOS Cache Cleanup Mistakes to Avoid
Cleaning storage is useful when done carefully. But several common habits can create more problems than they solve.
| Mistake | Why It’s Risky | Better Approach |
|---|---|---|
| Deleting all cache files | Can disrupt applications and force unnecessary rebuilding | Remove selected caches when needed |
| Clearing IDE indexes regularly | Can slow code analysis and project startup | Use IDE repair tools when problems occur |
| Removing Docker volumes without inspection | May permanently delete development databases | Inspect volumes and verify backups |
| Deleting project directories indiscriminately | May remove source code or configuration | Separate generated output from original files |
| Running aggressive cleanup commands | May remove more data than intended | Prefer dry runs and targeted commands |
| Assuming clearing cache improves speed | Applications may become slower while rebuilding caches | Clean to resolve a specific storage or application issue |
In particular, avoid blindly deleting everything inside ~/Library/Caches or removing system directories through Terminal.
macOS manages many temporary and system-generated files automatically. Manual cleanup should focus on identifiable problems and application-specific resources.
Final Thoughts
Developers can accumulate significant storage usage through package managers, browser caches, build artifacts, IDE indexes, and Docker resources.
However, effective macOS cleanup does not mean deleting every temporary-looking file.
Start by reviewing available storage and identifying unnecessary directories. Use supported cleanup commands for package managers and containers, and remove old build artifacts only when they can be regenerated.
For IDEs and Xcode, prefer targeted cleanup over routine cache deletion. For Docker, distinguish between disposable build resources and persistent data that must be preserved.
The best approach is simple: inspect first, clean selectively, and maintain reliable backups. This helps reclaim storage without disrupting the development environment you rely on.



Comments
Comments are provided by Disqus. Loading them connects to Disqus, which sets cookies and processes data under its own privacy policy.