Installing SageMath 9.5 in Ubuntu 22.04

The version of SageMath provided as a system package for Ubuntu 22.04 is 9.5; to install it, it suffices to run the command

sudo apt install sagemath-jupyter

If you would like to install version 9.7 instead, remove the system package sagemath if already installed, and follow the instructions below:

Installing SageMath 9.7 in Ubuntu 20.04 (and higher)

The version of SageMath provided as a system package is only 9.0 for Ubuntu 20.04 and 9.5 for Ubuntu 22.04. However building SageMath 9.7 from source in Ubuntu 20.04 or 22.04 is very easy.

First, install the dependencies, i.e. the Ubuntu packages required to build SageMath: simply open a terminal and type the single (long) line

sudo apt install bc binutils bzip2 ca-certificates cliquer cmake curl ecl eclib-tools fflas-ffpack flintqs g++ gengetopt gfan gfortran git glpk-utils gmp-ecm lcalc libatomic-ops-dev libboost-dev libbraiding-dev libbrial-dev libbrial-groebner-dev libbz2-dev libcdd-dev libcdd-tools libcliquer-dev libcurl4-openssl-dev libec-dev libecm-dev libffi-dev libflint-arb-dev libflint-dev libfreetype6-dev libgc-dev libgd-dev libgf2x-dev libgiac-dev libgivaro-dev libglpk-dev libgmp-dev libgsl-dev libhomfly-dev libiml-dev liblfunction-dev liblrcalc-dev liblzma-dev libm4rie-dev libmpc-dev libmpfi-dev libmpfr-dev libncurses5-dev libntl-dev libopenblas-dev libpari-dev libpcre3-dev libplanarity-dev libppl-dev libprimesieve-dev libpython3-dev libqhull-dev libreadline-dev librw-dev libsingular4-dev libsqlite3-dev libssl-dev libsuitesparse-dev libsymmetrica2-dev libz-dev libzmq3-dev libzn-poly-dev m4 make nauty openssl palp pari-doc pari-elldata pari-galdata pari-galpol pari-gp2c pari-seadata patch perl pkg-config planarity ppl-dev python3-distutils python3-venv r-base-dev r-cran-lattice singular sqlite3 sympow tachyon tar tox xcas xz-utils

To benefit from extra functionalities when running SageMath (e.g. exporting a Jupyter notebook to pdf), it is recommended to install some additional Ubuntu packages:

sudo apt install texlive-latex-extra texlive-xetex latexmk pandoc dvipng

Then you can download SageMath 9.7 sources and launch the build by typing (from you home directory or from the directory in which you want SageMath to be installed)

git clone --branch master
cd sage
make configure
MAKE="make -j8" make

The last command launches the build in parallel on 8 threads (as specified by -j8); adapt to your CPU (usually you may choose a number of threads that is twice the number of cores of your CPU). The build time is about half an hour on a modern CPU. Once it is finished, you can create a symbolic link by typing

sudo ln -sf $(pwd)/sage /usr/local/bin

Then you can change to any directory and start SageMath in Jupyter by running

sage -n

A Jupyter page should then open in your browser. Click on "New" and select "SageMath 9.7" to open a Jupyter notebook with a SageMath kernel.

Installing SageMath 9.8.beta* in Ubuntu 20.04 (and higher)

To install the latest development (beta) version, follow the same instructions as above for SageMath 9.7, except for the git clone line to be replaced by
git clone --branch develop