The gerometric structures, electronic and magnetic properties of the Co and Ni single doped and double doped ZnO nanowires are systematically studied by using density functional theory. It is found that the binding energies of the doped nanowires are negative, which indicates that the doping process is an exothermic reaction. The Co atom tends to occupy the intermediate position, while the Ni atom tends to occupy the surface position. All doped nanowires show direct band gap semiconductor behavior with the narrow energy gap. The magnetic moments of the nanowires mainly originate from the 3d orbitals of magnetic atoms. Two ferromagnetic and antiferromagnetic coupling states appear in the Co-doped nanowires, while three ferromagnetic, antiferromagnetic and paramagnetic coupling states appear in the Ni-doped nanowires.