You have to do this very early. It's hard to actually change the personalities, but you can have them learn what is right and what is wrong. It needs to be done early so that it becomes habitual.
As soon as you see selfish attitudes and meanness, you need to immediately confront the child and let him/her know that what he/she did was not right. That's the first step. The second step is to live what you preach. You need to show sharing and compassion to others in front of your child. Together, donate to the needy, and participate in community programs where your child can "see" you sharing your time and giving gifts to others.