Loading repository data…
Loading repository data…
sagemath / repository
This repository used to be the user-facing mirror of the Sage source tree. As Sage development migrated on 2023-02-01 from https://trac.sagemath.org/ to our new repository on GitHub, https://github.com/sagemath/sage, we have renamed and archived this repository.
"Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, and MATLAB"
Copyright (C) 2005-2022 The Sage Development Team
The Sage Library is free software released under the GNU General Public Licence GPLv2+, and included packages have compatible software licenses. Over 800 people have contributed code to Sage. In many cases, documentation for modules and functions list the authors.
The Sage Installation Guide provides a decision tree that guides you to the type of installation that will work best for you. This includes building from source, obtaining Sage from a package manager, using a container image, or using Sage in the cloud.
This README contains self-contained instructions for building Sage from source. It assumes that you have already cloned the git repository or downloaded the sources in the form of a tarball.
If you have questions or encounter problems, please do not hesitate to email the sage-support mailing list or ask on the Ask Sage questions and answers site.
Sage attempts to support all major Linux distributions, recent versions of macOS, and Windows (using Windows Subsystem for Linux or virtualization).
Detailed information on supported platforms for a specific version of Sage can be found in the section "Availability and installation help" of the release tour for this version.
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 preferred way to run Sage on Windows is using the 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 an alternative, you can also run Linux on Windows using Docker (see above) or other virtualization solutions.
If your Mac uses the Apple Silicon (M1, arm64) architecture:
If you set up your Mac by transfering files from an older Mac, make sure
that the directory /usr/local does not contain an old copy of Homebrew
(or other software) for the x86_64 architecture that you may have copied
over. Note that Homebrew for the M1 is installed in /opt/homebrew, not
/usr/local.
If you wish to use conda, please see the section on conda in the Sage Installation Manual for guidance.
Otherwise, using Homebrew ("the missing package manager for macOS") from
https://brew.sh/ required because it provides a version of gfortran with
necessary changes for this platform that are not in a released upstream
version of GCC. (The gfortran package that comes with the Sage
distribution is not suitable for the M1/M2.)
If your Mac uses the Intel (x86_64) architecture:
If you wish to use conda, please see the section on conda in the Sage Installation Manual for guidance.
Otherwise, we strongly recommend to use Homebrew ("the missing package
manager for macOS") from https://brew.sh/, which provides the gfortran
compiler and many libraries.
Otherwise, if you do not wish to install Homebrew, you will need to install
the latest version of Xcode Command Line Tools. Open a terminal window and
run xcode-select --install; then click "Install" in the pop-up window. If
the Xcode Command Line Tools are already installed, you may want to check if
they need to be updated by typing softwareupdate -l.
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 WSL.
More details, providing a background for these instructions, can be found in the section "Install from Source Code". in the Installation Guide.
Decide on the source/build directory (SAGE_ROOT):
On personal computers, any subdirectory of your :envvar:HOME
directory should do.
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 10 GB of free disk space.
The full path to the source directory must contain no spaces.
After starting the build, you cannot move the source/build directory without breaking things.
You may want to avoid slow filesystems such as network file systems (NFS) and the like.
[macOS] macOS allows changing directories without using exact capitalization.
Beware of this convenience when compiling for macOS. Ignoring exact
capitalization when changing into :envvar:SAGE_ROOT can lead to build
errors for dependencies requiring exact capitalization in path names.
Download/unpack or clone the sources.
Go to https://www.sagemath.org/download-source.html, select a mirror,
and download the file :file:sage-x.y.tar.gz.
This compressed archive file contains the source code for Sage and the source for all programs on which Sage depends.
After downloading the source tarball sage-x.y.tar.gz into
~/sage/:
$ cd ~/sage/
$ tar xf sage-x.y.tar.gz # adapt x.y; takes a while
This creates the subdirectory sage-x.y. Now change into it:
$ cd sage-x.y/ # adapt x.y
[Git] Alternatively, and required for Sage development, clone the Sage git repository:
$ ORIG=https://github.com/sagemath/sage.git
$ git clone -c core.symlinks=true --branch develop --tags $ORIG
This will create the directory sage. (See the section
Setting up git
and the following sections in the Sage Developer's Guide
for more information.)
Change into it and pick the branch you need, typically the latest development branch:
$ cd sage
$ 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
WSL bash using the WSL tar utility and not using other
Windows tools (including mingw). Likewise, when using git, it
is recommended (but not necessary) to use the WSL version of
git.
[Linux, WSL] Install the required minimal build prerequisites.
Compilers: gcc, gfortran, g++ (GCC 8.x to 12.x and recent
versions of Clang (LLVM) are supported).
See build/pkgs/gcc/SPKG.rst and
build/pkgs/gfortran/SPKG.rst
for a discussion of suitable compilers.
Build tools: GNU make, GNU m4, perl (including
ExtUtils::MakeMaker), ranlib, git, tar, bc.
See build/pkgs/_prereq/SPKG.rst for
more details.
Python 3.4 or later, or Python 2.7, a full installation including
urllib; but ideally version 3.8.x, 3.9.x, or 3.10.x, which
will avoid having to build Sage's own copy of Python 3.
See build/pkgs/python3/SPKG.rst
for more details.
We have collected lists of system packages that provide these build prerequisites. See, in the folder build/pkgs/_prereq/distros, the files arch.txt, debian.txt (also for Ubuntu, Linux Mint, etc.), fedora.txt (also for Red Hat, CentOS), opensuse.txt, slackware.txt, and void.txt, or visit https://doc.sagemath.org/html/en/reference/spkg/_prereq.html#spkg-prereq
[Git] If you plan to do Sage development or otherwise work with ticket branches and not only releases, install the bootstrapping prerequisites. See the files in the folder build/pkgs/_bootstrap/distros, or visit https://doc.sagemath.org/html/en/reference/spkg/_bootstrap.html#spkg-bootstrap
[Git] If you cloned the Sage repository using git, bootstrap the
source tree using the following command:
$ make configure
(If the bootstrapping prerequisites are not installed, this command will download a package providing pre-built bootstrap output instead.)
Sanitize the build environment. Use the command
$ env
to inspect the current environment variables, in particular PATH,
PKG_CONFIG_PATH, LD_LIBRARY_PATH, CFLAGS, CPPFLAGS, CXXFLAGS,
and LDFLAGS (if set).
Remove items from these (colon-separated) environment variables that Sage should not use for its own build. In particular, remove items if they refer to a previous Sage installation.
[WSL] In particular, WSL imports many items from the Windows
PATH variable into the Linux environment, which can lead to
confusing build errors. These items typically start with /mnt/c.
It is best to remove all of them from the environment variables.
For example, you can set PATH using the command:
$ export PATH=/usr/sbin/:/sbin/:/bin/:/usr/lib/wsl/lib/
[macOS with homebrew] Set required environment variables for the build:
$ source ./.homebrew-build-env
This is to make some of Homebrew's packages (so-called keg-only packages) available for the build. Run it once to apply the suggestions for the current terminal session. You may need to repeat this command before you rebuild Sage from a new terminal session, or after installing additional homebrew packages. (You can also add it to your shell profile so that it gets run automatically in all future sessions.)
Optionally, decide on the installation prefix (SAGE_LOCAL):
Traditionally, and by default, Sage is installed into the
subdirectory hierarchy rooted at SAGE_ROOT/local/.
This can be changed using ./configure --prefix=SAGE_LOCAL,
where SAGE_LOCAL is the desired installation prefix, which
must be writable by the user.
If you use this option in combination with --disable-editable,
you can delete the entire Sage source tree after completing
the build process. What is installed in SAGE_LOCAL will be
a self-contained installation of Sage.
Note that in Sage's build process, make builds and
installs (make install is a no-op). Therefore the
installation hierarchy must be writable by the user.
See the installa