Learn (something) the hard way

To learn something that is difficult or unpleasant by one’s own experience.

The young man learned things the hard way when he went to jail for stealing the computer.