"Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, and MATLAB"
Copyright (C) 2005-2020 The Sage Development Team
If you downloaded a binary (i.e. a version of SageMath prepared for a specific operating system), Sage is ready to start -- just open a terminal in the directory where you extracted the binary archive and type:
(Note that the first run will take more time, as Sage needs to get itself ready.)
If you downloaded the sources, please read below on how to build Sage and work around common issues.
Sage fully supports all major Linux distributions, recent versions of macOS, and Windows (using Cygwin, Windows Subsystem for Linux, or using virtualization).
We highly appreciate contributions to Sage that fix portability bugs and help port Sage to new platforms; let us know at the sage-devel mailing list.
The 64-bit version of Cygwin, also known as Cygwin64, is the current target for Sage support on Windows.
Download cygwin64 (do not get the 32-bit version; it is not supported by Sage).
setup-x86_64.exe graphical installer. Pick the default
options in most cases. At the package selection screen, use the
search bar to find and select at least the following packages:
Start the Cygwin terminal and ensure you get a working bash prompt.
Make sure the path of your Cygwin home directory does not contain space characters.
By default, your username in Cygwin is the same as your username in Windows. This might contain spaces and other traditionally non-UNIX-friendly characters, e.g., if it is your full name. You can check this as follows:
$ whoami Erik M. Bray
This means your default home directory on Cygwin contains this
username verbatim; in the above example,
/home/Erik M. Bray. It
will save some potential trouble if you change your Cygwin home
directory to something not containing any non-alphanumeric
characters, for example,
/home/embray. The easiest way to do
this is to first create the home directory you want to use instead,
then create an
/etc/passwd file specifying that directory as your
home, as follows:
$ whocanibe=embray $ mkdir /home/$whocanibe $ mkpasswd.exe -l -u "$(whoami)" | sed -r 's,/home/[^:]+,/home/'$whocanibe, > /etc/passwd
After this, close all Cygwin terminals (ensure nothing in
C:\cygwin64 is running), then start a new Cygwin terminal and
your home directory should have moved.
There are other ways to do this, but the above seems to be the simplest that's still supported.
Install the package manager
$ curl -OL https://rawgit.com/transcode-open/apt-cyg/master/apt-cyg $ install apt-cyg /usr/local/bin $ rm -f apt-cyg
An alternative to Cygwin is to use Windows Subsystem for Linux, which allows you to install a standard Linux distribution such as Ubuntu within your Windows. Then all instructions for installation in Linux apply.
As another alternative, you can also run Linux on Windows using Docker (see above) or other virtualization solutions such as the Sage virtual appliance.
Make sure you have installed the most current version of Xcode supported on your version of macOS. If you don't, either go to https://developer.apple.com/, sign up, and download the free Xcode package, or get it from Apple's app store.
You also need to install the "command line tools": After installing
xcode-select --install from a terminal window; then click
"Install" in the pop-up window. (When using Mountain Lion or earlier,
you need to install the command line tools from Xcode: run Xcode; then
from the File menu, choose "Preferences", then the "Downloads" tab,
and then "Install" the Command Line Tools.)
Optionally, you can consider installing Homebrew ("the missing package manager for macOS") from https://brew.sh/, which can provide libraries such as gfortran, gmp, etc.
Like many other software packages, Sage is built from source using
./configure, followed by
make. However, we strongly recommend to
read the following step-by-step instructions for building Sage.
The instructions cover all of Linux, macOS, and Cygwin.
More detailed instructions are contained in the Installation Guide.
Decide on the source/build directory (
For example, you could use
SAGE_ROOT=~/sage/sage-x.y, which we
will use as the running example below, where
x.y is the
current Sage version.
You need at least 6 GB of free disk space.
The path name must contain no spaces.
After starting the build, you cannot move the source/build directory without breaking things.
[Cygwin] Avoid building in home directories of Windows domain users or in paths with capital letters.
Download/unpack the sources.
After downloading the source tarball
$ cd ~/sage/ $ tar zxvf sage-x.y.tar.gz
This will create the subdirectory
[Git] Alternatively, clone the Sage git repository:
$ ORIG=https://github.com/sagemath/sage.git $ git clone -c core.symlinks=true --branch master $ORIG
This will create the subdirectory
cd sage/ and pick
the branch you need by doing
git checkout - typically you want
the latest development branch, thus do
git checkout develop.
[Windows] The Sage source tree contains symbolic links, and the build will not work if Windows line endings rather than UNIX line endings are used.
Therefore it is crucial that you unpack the source tree from the
Cygwin (or WSL)
bash using the Cygwin (or WSL)
and not using other Windows tools (including mingw). Likewise,
git, it is recommended (but not necessary) to use
the Cygwin (or WSL) version of
cd into the source/build directory:
$ cd sage*/
Optionally, decide on the installation prefix (
Traditionally, and by default, Sage is installed into the
subdirectory hierarchy rooted at
This can be changed using
SAGE_LOCAL is the desired installation prefix, which
must be writable by the user. (See the installation manual for
options if you want to install into shared locations such as
/usr/local/. Do not attempt to build Sage as root.)
[Git] If you cloned the Sage repository using
git, bootstrap the
source tree using:
$ make configure
[Linux, Cygwin] Install the required minimal build prerequisites.
g++ (a matching set of these
three will avoid the compilation of Sage-specific compilers -
unless they are too old). See the Installation Manual for a
discussion of suitable compilers.
Build tools: GNU
Python 3.4 or later, or Python 2.7, a full installation including
urllib; but ideally version 3.7.x, 3.8.x, or 3.9.x, which will
avoid having to build Sage's own copy of Python 3.
We have collected lists of system packages that provide these build prerequisites. See, in the folder build/pkgs/_prereq/distros, the files arch.txt, cygwin.txt, debian.txt (also for Ubuntu, Linux Mint, etc.), fedora.txt (also for Red Hat, CentOS), and slackware.txt.
Optional, but highly recommended: Make sure your system has an SSL library and its development files installed.
Like Python, on which it is based, Sage uses the OpenSSL library for added performance if made available by the operating system. It has been shown that Sage can be successfully built against other SSL libraries, with some of its features disabled.
Optional: It is recommended that you have both LaTeX and the ImageMagick tools (e.g. the "convert" command) installed since some plotting functionality benefits from it.
Optionally, review the configuration options, which includes many optional packages:
$ ./configure --help
Optional, but highly recommended: Set some environment variables to customize the build.
For example, the
MAKE environment variable controls whether to
run several jobs in parallel. On a machine with 4 processors, say,
export MAKE="make -j4" will configure the build script to
perform a parallel compilation of Sage using 4 jobs. On some
powerful machines, you might even consider
-j16, as building with
more jobs than CPU cores can speed things up further.
To reduce the terminal output during the build, type
V stands for "verbosity".)
For an in-depth discussion of more environment variables for building Sage, see the installation guide.
./configure, followed by any options that you wish to use. For example, to build Sage with
gf2xpackage supplied by Sage, use
At the end of a successful
./configure run, you may see messages
recommending to install extra system packages using your package
For a large list of Sage packages, Sage is able to detect whether an installed system package is suitable for use with Sage; in that case, Sage will not build another copy from source.
Sometimes, the messages will recommend to install packages that are
already installed on your system. See the earlier configure
messages or the file
config.log for explanation. Also, the
messages may recommend to install packages that are actually not
available; only the most recent releases of your distribution will
have all of these recommended packages.
Optional: If you choose to install the additional system packages,
a re-run of
./configure will test whether the versions installed
are usable for Sage; if they are, this will reduce the compilation
time and disk space needed by Sage. The usage of packages may be
./configure parameters (check again the output of
make. That's it! Everything is automatic and
non-interactive; but it will take a few hours (on a recent
The build should work fine on all fully supported platforms. If it does not, we want to know!
./sage to try it out.
make ptestlong to test all examples in the documentation
(over 200,000 lines of input!) -- this takes from 10 minutes to
several hours. Don't get too disturbed if there are 2 to 3 failures,
but always feel free to email the section of
contains errors to the sage-support mailing list.
If there are numerous failures, there was a serious problem with your build.
The HTML version of the documentation
is built during the compilation process of Sage and resides in the directory
Optional: If you want to build the PDF version of the documentation,
make doc-pdf (this requires LaTeX to be installed).
Optional: You might install optional packages of interest to you: type
./sage --optional to get a list.
If you have problems building Sage, check the Sage Installation Guide, as well as the version-specific Sage Installation FAQ in the Sage Release Tour corresponding to the version that you are installing.
Please do not hesitate to ask for help in the SageMath forum or the sage-support mailing list. The Troubleshooting section in the Sage Installation Guide provides instructions on what information to provide so that we can provide help more effectively.
If you'd like to contribute to Sage, we strongly recommend that you read the Developer's Guide.
Sage has significant components written in the following languages: C/C++, Python, Cython, Common Lisp, Fortran, and a bit of Perl.
Simplified directory layout (only essential files/directories):
SAGE_ROOT Root directory (sage-x.y.z in Sage tarball) ├── build │ └── pkgs Every package is a subdirectory here │ ├── atlas │ … │ └── zn_poly ├── configure Top-level configure script ├── COPYING.txt Copyright information ├── pkgs Source trees of Python distribution packages │ ├── sage-conf │ │ ├── sage_conf.py │ │ └── setup.py │ ├── sage-docbuild │ │ ├── sage_docbuild │ │ └── setup.py │ ├── sage-sws2rst │ │ ├── sage_sws2rst │ │ └── setup.py │ └── sagemath-standard │ ├── bin │ ├── sage │ └── setup.py ├── local (SAGE_LOCAL) Compiled packages are installed here │ ├── bin Executables │ ├── include C/C++ headers │ ├── lib Shared libraries │ ├── share Databases, architecture-independent data, docs │ │ └── doc Viewable docs of Sage and of some components │ └── var │ ├── lib/sage List of installed packages │ └── tmp/sage Temporary files when building Sage ├── logs │ ├── dochtml.log Log of the documentation build │ ├── install.log Full install log │ └── pkgs Build logs of individual packages │ ├── atlas-3.10.1.p7.log │ … │ └── zn_poly-0.9.p11.log ├── m4 M4 macros for configure │ └── *.m4 ├── Makefile Running "make" uses this file ├── README.md This file ├── sage Script to start Sage ├── src Monolithic Sage library source tree │ ├── bin Scripts that Sage uses internally │ ├── doc Sage documentation sources │ └── sage The Sage library source code ├── upstream Source tarballs of packages │ ├── atlas-3.10.1.tar.bz2 │ … │ └── zn_poly-0.9.tar.bz2 └── VERSION.txt
For more details see our Developer's Guide.
This is a brief summary of the Sage software distribution's build system. There are two components to the full Sage system--the Sage Python library and its associated user interfaces, and the larger software distribution of Sage's main dependencies (for those dependencies not supplied by the user's system).
Sage's Python library is built and installed using a
setup.py script as is
standard for Python packages (Sage's
setup.py is non-trivial, but not
Most of the rest of the build system is concerned with building all of Sage's
dependencies in the correct order in relation to each other. The dependencies
included by Sage are referred to as SPKGs (i.e. "Sage Packages") and are listed
The main entrypoint to Sage's build system is the top-level
Makefile at the
root of the source tree. Unlike most normal projects that use autoconf (Sage
does as well, as described below), this
Makefile is not generated. Instead,
it contains a few high-level targets and targets related to bootstrapping the
system. Nonetheless, we still run
make <target> from the root of the source
tree--targets not explicitly defined in the top-level
Makefile are passed
through to another Makefile under
build/make/Makefile is generated by an autoconf-generated
configure script, using the template in
includes rules for building the Sage library itself (
make sagelib), and for
building and installing each of Sage's dependencies (e.g.
configure script itself, if it is not already built, can be generated by
bootstrap script (the latter requires GNU autotools being installed).
Makefile also takes care of this automatically.
To summarize, running a command like
make python3 at the top-level of the
source tree goes something like this:
./configurewith any previously configured options if
build/makeand run the
installscript--this is little more than a front-end to running
make -f build/make/Makefile python3, which sets some necessary environment variables and logs some information
build/make/Makefilecontains the actual rule for building
python3; this includes building all of
python3's dependencies first (and their dependencies, recursively); the actual package installation is performed with the
It is not supported to move the
after starting the build. If you do move the directories, you will
have to rebuilt Sage again from scratch.
If you copy the
sage script or make a symbolic link to it, you
should modify the script to reflect this (as instructed at the top of
the script). It is important that the path to Sage does not have any
spaces and non-ASCII characters in it.
For a system-wide installation, you have to build Sage as a "normal" user and then as root you can change permissions. Afterwards, you need to start up Sage as root at least once prior to using the system-wide Sage as a normal user. See the Installation Guide for further information.
Your local Sage install is almost exactly the same as any "developer" install. You can make changes to documentation, source, etc., and very easily package the complete results up for redistribution just like we do.
To make a binary distribution with your currently installed packages, visit sagemath/binary-pkg.
(Obsolete, probably broken) To make your own source tarball of Sage, type:
$ sage --sdist
The result is placed in the directory
All software included with Sage is copyrighted by the respective authors and released under an open source license that is GPL version 3 or later compatible. See COPYING.txt for more details.
Sources are in unmodified (as far as possible) tarballs in the
upstream/ directory. The remaining description, version
information, patches, and build scripts are in the accompanying
build/pkgs/<packagename> directory. This directory is
part of the Sage git repository.