We learn about how to relate to others as very young children, by observing (and by imitating) how the important people in our lives (parents, siblings, other relatives, child care workers, teachers, coaches, etc) manage their relationships. For example, if our parents are always arguing with each other, we learn that as a model of how to behave.
Clearly, there are genetic components also. Animal models demonstrate that the capacity for affective empathy is genetically determined, and related to the neurohormones oxytocin and vasopressin. So if our parents have low levels of affective empathy, it is likely that we will also.