First step is to download the latest stable version from here:
https://www.open-mpi.org/software/ompi/v4.0/
After opening the tarball, go into the directory and configure:
./configure --prefix=/opt/openmpi-4.X.X --enable-mpi1-compatibility
Substitute X.X for the actual version being installed. This will allow you to have multiple versions of openmpi on a system, which may be needed for existing applications or research projects. The mpi1 compatibility thing is only needed if you plan to install scalapack.
Next:
make
sudo make install