Gravitational potential energy
Gravitational potential energy, commonly noted $U$, refers to the energy incorporated in a system as a result of the gravitational attraction between its elements.
Zero reference point
Generally, we define the zero reference point:
Since there is no gravitational interaction when objects are at an infinite distance from each other.
Then, the gravitational potential energy of a system measures the amount of work done by gravitational forces to move all masses of the system away from each other until the distance between them is infinite.
Basic case: 2 point masses
For two point masses $m$, $M$, we can calculate the gravitational potential energy of the system mostly easily by constructing a cartesian coordinate system with one of the point masses, $M$, at the origin.
Then, if $m$ has position vector $ \mathbf r_1$:
$$\mathbf F_g(m)=-G\frac{Mm}{r_1^2}\hat{\mathbf r}_1$$
The potential energy of the system is:
$$U=-\int_{\infty}^{r_1}\left(-G\frac{Mm}{r^2}\right) \hat{\mathbf r} \cdot dr=-G\frac{Mm}{r}$$
$$\hat{\mathbf r} \cdot dr = dr$$
Many point masses
Recall the gravitational potential energy between 2 point masses is
Applying the formula to all pairs of point masses in the system:
We can similarly derive a formula for the gravitational potential energy of a point mass external to the system:
Continuous mass distribution
Any generic mass system can be modelled by a continuous mass distribution, with $\rho=0$ where there is no mass.
If the density at point with position vector $\mathbf{r}$ is $\rho(\mathbf{r})$:
$dV=dr^3$: infinitesimal volume
Gravitational potential
If a test mass $m$ has gravitational potential energy $U(\mathbf{r})$ at a point, then the gravitational potential at that point is
$$\Phi(\mathbf{r})=\frac{U(\mathbf{r})}{m}$$
For another test mass $m_1$, the gravitational potential energy at the same point is then simply: