Dysregulation ofHDAC4expression and/or nucleocytoplasmic shuttling results in impaired neuronal morphogenesis and long-term memory inDrosophila melanogaster. A recent genetic screen for genes that interact in the same molecular pathway asHDAC4identified the cytoskeletal adapterAnkyrin2 (Ank2). Here we sought to investigate the role of Ank2 in neuronal morphogenesis, learning and memory. We found that Ank2 is expressed widely throughout theDrosophilabrain where it localizes predominantly to axon tracts. Pan-neuronal knockdown of Ank2 in the mushroom body, a region critical for memory formation, resulted in defects in axon morphogenesis. Similarly, reduction of Ank2 in lobular plate tangential neurons of the optic lobe disrupted dendritic branching and arborization. Conditional knockdown of Ank2 in the mushroom body of adultDrosophilasignificantly impaired long-term memory (LTM) of courtship suppression, and its expression was essential in the γ neurons of the mushroom body for normal LTM. In summary, we provide the first characterization of the expression pattern of Ank2 in the adultDrosophilabrain and demonstrate that Ank2 is critical for morphogenesis of the mushroom body and for the molecular processes required in the adult brain for the formation of long-term memories.Supplementary InformationThe online version contains supplementary material available at 10.1186/s13041-023-01026-w.