Metal oxides suffering from oxygen molecule chemisorption display environment-dependent metastability, leading to unstable resistive memory characteristics and performance degradation. To obtain ambient-independent characteristics, we introduced nitrogen into ZnO resistive memory devices, compensating for the native defects and suppressing oxygen chemisorption, giving rise to a significant improvement in switching behavior without undesired surface effects. Moreover, by thermal activation of the nitrogen doping via annealing, an increased yield ratio from 50% to 82%, a reduced current compliance from 15 mA to 5 mA, and more stable cycling endurance are obtained. Our findings give physical insight into designing resistive memory devices.