Long lasting immunity is obtained by means of the adaptive immune system, and mainly involves the development of antibodies that identify specific parts (epitopes) of the pathogen's proteins. Common cold is typically caused by a type of virus called rhinovirus. Viruses have very high mutation rates, which alter the sequence of the virus proteins, modifying their antigenic properties. This consequently alters the ability of antibodies to recognize a particular antigen.
In other words, we _do_ develop long lasting immunity against the virus that causes us a cold today, but the virus that causes us a cold a few months later is somewhat different, and the adaptive immune system has to start from scratch.