This is only half related to aviation, but I'll bite.
As the Earth is close enough to a sphere (but not exactly..) it is simplest to assume that the longest flight would be from one end of an antipode to the other.
According to this site, such a flight would be approximately 20,000 km:
There are no non-stop scheduled flights between any two antipodal locations by commercial airline service. A hypothetically perfect antipode flight would be Tangier Ibn Battouta Airport, Morocco to Whangarei Aerodrome, New Zealand (approximately 20000 km flight).
The Boeing 777-200LR is the aircraft with the longest range at just under 17,400 km (but see also this question which explains why that number can change). So with present technology (or economics), such a flight is not really a possibility.