At birth the piglet's immune system is immature and it is dependent upon passive maternal protection until weaning. The piglet's mucosal immune system develops over the first few weeks but has not reached maturity at weaning ages which are common on commercial farms. At weaning piglets are presented with a vast and diverse range of microbial and dietary/environmental antigens. Their ability to distinguish between antigens and mount a protective response to potential pathogens and to develop tolerance to dietary antigens is critical to their survival and failure to do so is reflected in the high incidence of morbidity and mortality in the post-weaning period. A growing recognition that the widespread use of antibiotics to control infection during this critical period should be controlled has led to detailed studies of those factors which drive the development of the mucosal immune system, the role of gut microbiota in driving this process, the origin of the bacteria that colonise the young piglet's intestine and the impact of rearing environment. This review briefly describes how the mucosal immune system is equipped to respond "appropriately" to antigenic challenge and the programmed sequence by which it develops. The results of studies on the critical interplay between the host immune system and gut microbiota are discussed along with the effects of rearing environment. By comparing these with results from human studies on the development of allergies in children, an approach to promote an earlier maturation of the piglet immune system to resist the challenges of weaning are outlined.