The social environment is a major determinant of morbidity, mortality and Darwinian fitness in social animals. Recent studies have begun to uncover the molecular processes associated with these relationships, but the degree to which they vary across different dimensions of the social environment remains unclear. Here, we draw on a long-term field study of wild baboons to compare the signatures of affiliative and competitive aspects of the social environment in white blood cell gene regulation, under both immune-stimulated and non-stimulated conditions. We find that the effects of dominance rank on gene expression are directionally opposite in males versus females, such that high-ranking males resemble low-ranking females, and vice versa. Among females, rank and social bond strength are both reflected in the activity of cellular metabolism and proliferation genes. However, while we observe pronounced rank-related differences in baseline immune gene activity, only bond strength predicts the fold-change response to immune (lipopolysaccharide) stimulation. Together, our results indicate that the directionality and magnitude of social effects on gene regulation depend on the aspect of the social environment under study. This heterogeneity may help explain why social environmental effects on health and longevity can also vary between measures. This article is part of the theme issue `The centennial of the pecking order: current state and future prospects for the study of dominance hierarchies’.