A laboratory XRF analysis system employing an HgI 2 spectrometer detector has been built. The system consists of an x-ray generator tube, a rotating carousel holding multiple XRF targets, and a probe head containing the HgI 2 detector. Tests have been performed on several samples, under vacuum, helium and nitrogen ambient atmospheric conditions. This is of particular interest, since the applications for such an XRF system include operation under different ambient conditions. For applications in terrestrial and space planetary exploration, the expected temperatures and gas ambient will vary widely. Comparative analyses using the various gases were made on spectra obtained from standard geological samples.