In "points in algebraic geometry why shift from m-spec to spec", Anton said that the global sections functor $\Gamma: \mathrm{LRSp} \to \mathrm{CRing}$ is left adjoint to the Spec functor $\mathrm{Spec}:\mathrm{CRing } \to \mathrm{LRSp}$, where $\mathrm{LRSp}$ is the category of locally ringed spaces.

It is an exercise in Hartshorne (II 2.4) to show that this is true when $\mathrm{LRSp}$ is replaced with the category of schemes. I can solve this exercise, but my argument relies heavily on being able to cover a scheme with open affine schemes.

Can anyone point me towards a reference where this is proved or give me some hints?