Your book is being extremely sneaky! This in fact a highly nontrivial construction. One good source to read about it is the end of Chapter I in the book Moduli of Curves by Joe Harris and Ian Morrison.
Curiously, long before anyone constructed $M_g$, Riemann was happily computing that its dimension equals $3g-3$. Riemann's argument is very nicely explained by user Brenin in another question on this site, which I can't find just at the moment.
The first construction of $M_g$, if I remember correctly, is due to Bers around 1950. This construction is analytic: it shows that the Teichmueller space $T_g$ is an open subset of $\mathbf C^{3g-3}$, and $M_g$ is then a quotient of $T_g$ by a discrete group action.
The first purely algebraic construction of $M_g$ was then given by Mumford in the early 1960s, using Geometric Invariant Theory. The idea here is that all smooth curves of genus $g$ can be embedded in a projective space $\mathbf P^N$ of fixed dimension (depending on $g$). So one can consider the corresponding component of the Hilbert scheme of $\mathbf P^N$; the moduli space $M_g$ is then the quotient of (an open subset of) this component by the action of the group $SL(N+1)$.
Anyway, the moral is: $M_g$ is not easy!