In the era of knowledge economy, how to promote knowledge sharing behavior of university students deserves close attention from academic and practical circles. As a character strength, purpose in life can predict individuals' thriving and positive development, but its predictive effect on knowledge sharing behavior has not been explored. This study investigated the association between purpose in life (meaningfulness, goal orientation, and beyond‐the‐self) and knowledge sharing behavior, and the potential mediating effect of gratitude. Data were collected from 493 students (mean age = 20.86, standard deviation= 1.69) from two universities in the Hunan province of China. They completed the scales of purpose in life, gratitude, and knowledge sharing behavior in June 2022. This study conducted structural equation model analysis to test the hypothetical model. The results showed that goal orientation and beyond‐the‐self positively predicted knowledge sharing behavior, and gratitude partially mediated the association between goal orientation and knowledge sharing behavior, and beyond‐the‐self and knowledge sharing behavior. The findings highlight the importance of purpose in life and gratitude in promoting knowledge sharing behavior among university students.