"Could not find a compiler version matching 0.8.2" error from Truffle on macOS when not using sudo

1.3k views Asked by At

If I don't use sudo, truffle compile gives me an error: truffle compile output.

With sudo there is no error: sudo truffle compile output.

Why does that happen?

1

There are 1 answers

0
cameel On

This is caused by wrong permissions on some of Truffle's files/dirs in your system. They're probably owned by root and Truffle cannot write there. Simply removing the configuration should fix the issue:

sudo rm -rf ~/Library/Preferences/truffle-nodejs

Alternatively you might use chown to change ownership of those files but if you never modified the config manually just removing it is simpler and Truffle will recreate it for you and also redownload the compiler binaries when needed.

This was recently reported by many users in Can't compile solc version "^0.8.9" #4431 but does not really seem to be a bug in Truffle itself. Not sure why it was so widespread - is some popular tutorial telling people to run Truffle with sudo or something? If you do, Truffle will create some files as root and won't be able to overwrite them or create new ones unless you keep running it with sudo.