Heat capacity in canonical ensemble?

This is a problem from Understanding molecular simulations by Frenkel and Smit.

Show that the heat capacity can be calculated from fluctuations in the total energy of a canonical ensemble. $$C_v=\frac{<U^2>-<U>^2}{k_BT^2}.$$

I know the following $$C_v=\left(\frac{dU}{dT}\right)_V$$. How do I calculate slope in a statistical ensemble. What am I missing here?

If $Z = \sum_\mu \mathrm e^{-\beta E_\mu}$ is the partition function in the canonical ensemble, then $$U = \langle U \rangle = -\frac{\partial}{\partial \beta} \ln Z \text{ and}\\ \Delta U^2 = \langle U^2 \rangle - \langle U \rangle^2 = \frac{\partial^2}{\partial\beta^2} \ln Z \;.$$ (If you don't know why, prove this by calculating the derivatives.)