One of my favourite parts of Marcus Aurelius' Meditations is this one:

Begin each day by telling yourself: Today I shall be meeting with interference, ingratitude, insolence, disloyalty, ill-will, and selfishness – all of them due to the offenders’ ignorance of what is good or evil. But for my part I have long perceived the nature of good and its nobility, the nature of evil and its meanness, and also the nature of the culprit himself, who is my brother (not in the physical sense, but as a fellow creature similarly endowed with reason and a share of the divine); therefore none of those things can injure me, for nobody can implicate me in what is degrading. Neither can I be angry with my brother or fall foul of him; for he and I were born to work together, like a man’s two hands, feet or eyelids, or the upper and lower rows of his teeth. To obstruct each other is against Nature’s law – and what is irritation or aversion but a form of obstruction.
In other words, you're going to deal with people you don't like, and people who don't like you.

This article from Lifehacker is along the same lines:

Remember that it is impossible to please everyone,” Chloe Brotheridge, a hypnotherapist and anxiety expert, tells us. “You have your own unique personality which means some people will love and adore you, while others may not.” Of course, while this concept is easy to understand on its face, it’s difficult to keep your perspective in check when you find you’re, say, left out of invitations to happy hours with co-workers, or getting noncommittal responses from potential new friends, or you overhear your roommates bad-mouthing you. Rejection is painful in any form, whether it be social or romantic, and it’s a big ego blow to get bumped from the inner circle.
I had a good friend of mine cut me off a few years ago. This was a guy who my kids called 'uncle', without him actually being a family member. But hey, no hard feelings:
So, it’s not really that it’s not you but them, so much as it’s both you and them. “This person, this situation, where they are in their life, it’s not compatible to where you are,” Jennifer Verdolin, an animal behavior expert and adjunct professor at Duke University, tells us. “We have preferences in terms of personality, and that’s not to say that your personality is bad. It’s different from mine, and I prefer to hang around people who are similar to me.”
There's incompatibility, different life stages, and there's just being a dick:
While you shouldn’t always blame yourself if someone doesn’t like you, if you’re finding this is a pattern, you may want to take an unbiased look at your own behavior. “When I put people in a [therapy] group, I get to see immediately what problems or tics or bad social habits they have,” Grover says. He recalls a successful, handsome male patient of his who was having trouble holding onto romantic relationships. Though they were unable to solve the problem together in individual therapy, Grover managed to convince the patient to join a group. “Within five minutes, I was horrified,” Grover says. “He gets very anxious in front of people, and to camouflage his anxiety he becomes overly confident, which comes across as arrogant. The women in the group commented that he was becoming less popular the more they got to know him.”
You can't please all of the people all of the time, but you can introspect and know yourself. Then you're in a stronger position to say what (and who) you like, and for what reasons.

Final thought? It’s worth being nice to people as you never know when they’re going to be in a position to do you a favour. It doesn’t, however, mean you have to hang out with them all of the time.

Source: Lifehacker