"ParserError: Expected '{' but got reserved keyword 'override'"

Hello, a friend and I are learning to use OpenZeppelin for the first time and could not find a way to fix this error. It is showing up when we use the OpenZeppelin ERC20 examples.

:computer: Environment
Both my friend and I are using VSCode, I am on Windows and he is on Mac/Linux. (Tried both.)
Truffle v5.3.7
Solidity - 0.5.1
Node v14.17.0

:memo:Details
This is the exact error that appears:

$ truffle migrate

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
✔ Downloading compiler. Attempt #1.
> Compiling @openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\Token.sol

@openzeppelin/contracts/token/ERC20/ERC20.sol:60:41: ParserError: Expected '{' but got reserved keyword 'override'
function name() public view virtual override returns (string memory) {
                                    ^------^

Compilation failed. See above.

My friend and I are tearing our hair out over this, and we’ve tried as many simple fixes as we could. I think it is us, and not the code provided, but I am not sure what to do.

:1234: Code to reproduce

This is the code I believe that it is referencing:

    function name() public view virtual override returns (string memory) {
        return _name;
    }

If you need to see anything else, leave a comment I will respond ASAP. Thanks in advance!

FIXED: Don’t forget to upgrade your solidity! We were using the wrong version, but this error can also happen when you mismatch the version with what is in the truffle config file.

1 Like