Based on the density functional theory, the geometries, electrical structures and optical properties of Co-doped MgF2 system (Co:MgF2) are studied by first-principles ultra-soft pseudopotential plane-wave approach. With Co-doping increasing, a tetragonal-rhombic structural transition is obtained in Co:MgF2. The band gap decreases with increasing Co-doping, and a semiconductor-conductor transition is observed. Also, the calculations show-that the static dielectric constant and the absorption coefficient can be remarkably modulated by Co-doping, indicating the potential applications of Co:MgF2 optical system.