Optical fiber is widely used in optical coherence tomography (OCT) to propagate light precisely with low attenuation and low dispersion. However, the total optical path length within the optical fiber varies in accordance with changes of the temperature. This leads changes in the total optical travel path of the interfering signals and results in shifting of OCT image position to an unintended depth pixel value. In this paper, we presented the temperature-based automatic path length compensating method in OCT to limit the external temperature effect and control the image position in micro-scale without manual movement of optical components. By utilizing developed hardware and software of automatic temperature control system, the external temperature of optical fiber is precisely regulated that evokes thermal expansion and finally changes the physical length of fiber, which is main mechanism of temperature-based path length compensating method. The effectiveness of the presented method was verified by two-dimensional OCT images of mirror and in vivo retina. The obtained results confirmed the path length variance due to temperature change is computable and can be regulated in real-time for whole pixel range of OCT image. Therefore, the proposed temperature-based path length compensating method can be used as an alternative method to precisely control the position of OCT image, while eliminating the effect of external temperature and apply to effectively configuring compact optical systems.