All commands in one place for building sagemath on Ubuntu.
SageMath official website
For any doubts refer to the following page.
http://doc.sagemath.org/html/en/installation/source.html#system-specific-requirements
git patch openssl libssl-dev libz-dev bc libbz2-dev liblzma-dev libgmp-dev \
libffi-dev libgf2x-dev libcurl4-openssl-dev curl yasm
sudo apt install texlive ffmpeg dvipng imagemagick openssh-server openssh-client tk tk-dev
tar xvf sage-x.y.tar
cd sage-x.y
make -jN # N is the number of cores
./sage -i pyopenssl
ln -s /path/to/sage-x.y/sage /usr/local/bin/sage
./sage -n jupyter
jupyter notebook
make -j8 on AMD Ryzen 1700x, 3.85 Ghz : 65 mins
make ptestlong : parallel test run, 25 mins