I’d recommend you to run precisely the script in the ccache link above, I always do this without thinking and it works like a charm.
Specifically, in the terminal, I go to the PyTorch folder, I copy & paste all the code between then and fi in the ccache link, then I run export PATH=~/ccache/lib:$PATH. It works a 100% of times, in several machines, I never spent any second trying to understand why !
BTW, whenever you close the terminal, you should run export PATH=~/ccache/lib:$PATH again for ccache to work.