The go clean command is “used to remove object files and cached files created during the build process.” It can help you clean up your project directory and free up disk space by deleting compiled binary files, test binaries, and other temporary files.
The go clean command does not remove dependencies or packages installed with go get.
Syntax
go clean [flags] [packages]
- flags: Optional flags to modify the behavior of the command.
- packages: The list of packages to clean. If no packages are specified, the command defaults to the current package (the package in the current directory).
Useful flags of ‘go clean command’
- -i: Remove the corresponding installed archive or binary (what ‘go install’ would create).
- -r: Clean recursively, i.e., apply the clean command to all dependencies.
- -cache: Clean the entire module cache (usually located in $GOPATH/pkg/mod), including both cached packages, builds, and cached downloaded modules.
- -testcache: Clean the entire test result cache.
- -modcache: Clean the entire module download cache.
Example
To clean the current package and remove the corresponding installed binary, you can use this command: go clean -i.
Please note that go clean does not uninstall packages or dependencies installed with go get.
To remove those, you’ll need to manually delete their directories, as described in the previous answer.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.