Development of “smart” noninvasive bioimaging probes for trapping specific enzyme activities is highly desirable for cancer therapy in vivo. Given that β-galactosidase (β-gal) is an important biomarker for cell senescence and primary ovarian cancers, we design an enzyme-activatable ratiometric near-infrared (NIR) probe (DCM-βgal) for the real-time fluorescent quantification and trapping of β-gal activity in vivo and in situ. DCM-βgal manifests significantly ratiometric and turn-on NIR fluorescent signals simultaneously in response to β-gal concentration, which makes it favorable for monitoring dynamic β-gal activity in vivo with self-calibration in fluorescent mode. We exemplify DCM-βgal for the ratiometric tracking of endogenously overexpressed β-gal distribution in living 293T cells via the lacZ gene transfection method and OVCAR-3 cells, and further realize real-time in vivo bioimaging of β-gal activity in colorectal tumor-bearing nude mice. Advantages of our system include light-up ratiometric NIR fluorescence with large Stokes shift, high photostability, and pH independency under the physiological range, allowing for the in vivo real-time evaluation of β-gal activity at the tumor site with high-resolution three-dimensional bioimaging for the first time. Our work provides a potential tool for in vivo real-time tracking enzyme activity in preclinical applications.