Avermectin is a dual-purpose antibiotic used in agriculture and livestock. Its widespread and massive use leads to its accumulation in the biological chain, causing significant impact on human food safety. Therefore, there is a need to establish a rapid and effective method for the detection of avermectin. In this study, a combination of the GO-SELEX and CE-SELEX methods was employed to screen aptamers for avermectin B1a from a ssDNA random library. After 7 rounds of selection, three aptamers with high enrichment and low homogeneity were chosen for affinity analysis, and the aptamer Seq 1 with the highest affinity was obtained. Optimized and truncated Seq 1 yielded the final high-affinity and specific aptamer, Seq 1–1. Based on the inhibitory effect of Seq 1–1 aptamer on the peroxidase-like activity of ruthenium nanoparticles (Ru NPs), for the first time, we developed a simple and stable colorimetric aptasensor for the detection of residual avermectin B1a. The linear range of the colorimetric sensor is 6.25–100 nM, with a minimum detection limit of 5.86 nM. In addition, the constructed sensor was used to detect avermectin B1a in milk and tomatoes, with a recovery rate of 92.86 %–101.49 %. This indicates that the sensor has broad application prospects in the detection of avermectin samples in animal husbandry and agriculture.