after a year or two developing with GO I had a look at my $GOPATH directory size and was surprised to see it was growing to a 4GB.
I understand that disk space is supposed (and it's not that much on this 128GB laptop SSD) to be cheap but still.
So my questions is, is there some good practice to manage the size $GOPATH directory ?
Would restarting from scratch would be a good idea? (although could be very much time consuming)
Your statement, that deleting the GOPATH
would be time consuming, sounds like you are managing the dependencies of your Go projects with plain go get ...
. In my environment I do two things to make the GOPATH
ephemeral.
Don't use plain go get
for dependency management. Go 1.6 introduced the /vendor
directory. Together with a dependency management tool like Glide every dependency for a certain project lies withing the project directory.
This means, if don't need a dependency anymore you can wipe the vendor
directory of the project and download the dependencies again. Therefore you only have dependencies on your disk, which you actually need.
Also, if you stop working on a project and delete it from your disk, the dependencies also get deleted.
You can specify multiple paths in the GOPATH
. Like the PATH
environment variable you can split them by a colon. The interesting thing is, that Go uses the first path for downloading projects. On my machine the GOPATH
looks like $HOME/.gopath:$HOME/projects
. So if you put all your actual projects into the second directory, you will have an clear separation between your projects and dependencies. Thus you could wipe the first directory from time to time, but don't need to fear that you have to clone every of your projects, again.
These two things don't help to reduce the disk usage of your Go projects and their dependencies, but you get a better overview whats actually needed and makes you able to delete the dependency directory whenever you like.