The digestive tracts of many animals are epithelial tubes with specialized compartments to break down food, remove wastes, combat infection, and signal nutrient availability. C. elegans possesses a linear, epithelial gut tube with foregut, midgut, and hindgut sections. The simple anatomy belies the developmental complexity that is involved in forming the gut from a pool of heterogeneous precursor cells. Here, I focus on the processes that specify cell fates and control morphogenesis within the embryonic foregut (pharynx) and the developmental roles of the pharynx after birth. Maternally donated factors in the pregastrula embryo converge on pha-4, a FoxA transcription factor that specifies organ identity for pharyngeal precursors. Positive feedback loops between PHA-4 and other transcription factors ensure commitment to pharyngeal fate. Binding-site affinity of PHA-4 for its target promoters contributes to the progression of the pharyngeal precursors towards differentiation. During morphogenesis, the pharyngeal precursors form an epithelial tube in a process that is independent of cadherins, catenins, and integrins but requires the kinesin zen-4/MKLP1. After birth, the pharynx and/or pha-4 are involved in repelling pathogens and controlling aging.