Installing Sage
- Go to the Official Sage Installation Page.
- In the line Linux macOS Windows, click on your operating system.
- The instructions below are for your convenience only. Compare to the official documentation when running, and let me know if there are any changes, differences, or issues.
Installing in Windows
Follow the instructions at https://doc.sagemath.org/html/en/installation/index.html
This involves installing and activating the Windows Subsystem for Linux (WSL). This will take a little time, but will provide you access to a full linux distribution inside Windows.
-
Install Ubuntu Linux on WSL
- Option 1: Open the Windows Store and search for Ubuntu
-
Option 2: Open the
PowerShellapplication and runwsl --install -
Reboot your machine if needed
-
Search your Start Menu for
Ubuntu. Right click and selectadd link to taskbarso you can find this more easily. Then left click to open it. -
Inside
Ubunturun the commands from the official Sage Math installation page. The code at the time of writing is given below, but check the official page and use their code insteadcurl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash Miniforge3-$(uname)-$(uname -m).shThere will be several questions - accept the license terms - save to the default directory - Important: Select yes when asked whether to proceed with initialization.
If you said *no* to initialization, you should run `miniforge3/condabin/conda init`You may also need to restart the Ubuntu application (called the shell). Then run the following:
conda create -n sage sage python=3.12Again you will need to type
yto proceed.
Download and installation will take a little while.
When the installation ends, run:conda activate sage -
To run Sage, first open Ubuntu. Then run the following command:
jupyter notebook --NotebookApp.token='Risheequai3diuGhaiMuano4EeCh7geB'Once its finished setting up, you can click on the following link to open the Jupyter Notebook application
http://localhost:8888/tree?token=Risheequai3diuGhaiMuano4EeCh7geB
That command includes a hardcoded authentication token, which should be secure enough for local use with a single user. For more security, run
jupyter notebookYou will then need to read through the output to find the randomly generated token as below
To access the server, ... Or copy and paste one of these URLs: http://localhost:8888/tree?token=b2b6a...43aCopy the entire address into a web browser, and load it.
Installing in macOS
Follow the instructions at https://doc.sagemath.org/html/en/installation/index.html
It is easist to use the binary build files. According to SageMath, it is signed and notarized for use with the macOS ecosystem.
- If you have a M1, M1X or M2 processor select the
...arm64.dmgfile - If you have an Intel processor select
...x86_64.dmg
After downloading, install it by opening it, and dragging the SageMath icon to the Applications folder.
- Double click on the program icon to run Sage.
- Open as a notebook
- Select a directory where you want your worksheet files saved.
Running Sage in a Jupyter Notebook
Starting Sage
If prompted when opening Sage, you want to run it using a Jupyter Notebook.
-
Windows:
-
Open
Ubuntu, then runjupyter notebook --NotebookApp.token='Risheequai3diuGhaiMuano4EeCh7geB' -
In a web browser, open http://localhost:8888/tree?token=Risheequai3diuGhaiMuano4EeCh7geB
-
-
macOS:
-
Click on the application icon.
-
Open as a notebook
-
When Jupyter opens, you will see your a user directory.
-
macOS, this will be the directory you selected.
-
Windows, this will be a hidden directory you cannot access.
You will need to download worksheets to a normal directory.
You can open an existing notebook (with a .ipynb extension), or you can create a new one.
-
Use a Sage kernel to run Sage code.
-
Use a Python kernel to run pure Python code.
Understanding the Jupyter Notebook Interface
Home Screen
When you start Sage, you will see a screen with the word Jupyter at the top. Below, you will see a (possibly empty) folder with unfamiliar contents.
- Once you have created notebooks, you can open them by clicking on them here, and you can organize them into directories.
On the right side of the screen you will see several options:
-
New
- Select Python 3 to run standard Python code
- Select SageMath 10.7 to run Sage Math code
-
Upload a file from your local hard drive.
Inside a Notebook
- File commands:
- save file
- download -- This is the only way to share worksheet files if you are using Windows.
- Cell commands
- insert blank cell
- cut/copy/paste cell
- run current cell
- Runtime commands
- stop execution
- restart kernel
- restart and run all cells
- There is a Dropdown that lets you select code or markdown.
- Code cells contain code that is executed when you click run
- Markdown cells contain text that is nicely formatted when you click run
- At the far right, you will see SageMath 10.7. This tells you the existing Kernel. You use a Sage kernel to run Sage code, and a Python kernel to run pure Python.