A working (or studying) mathematician's guide to getting your hands on SageMath
Here is a description of various possibilities to get access to SageMath. There are two main ways of using this software:
- in a Terminal (or console), executing one command after the other. Once you start SageMath (often by typing "sage" + Enter in a command prompt), you can type "1+2" + Enter, to do your first computation.
- in a Jupyter notebook (a file ending on .ipynb), where you can have cells with different bits of code together with nicely formatted text, pictures etc. When creating a new notebook you should select a SageMath kernel. Then you can type "1+2" in the first cell and press Shift+Enter to see the result.
Below we explain how to get access to either of these formats. Once this is accomplished, you can read e.g. here for a quick introduction to some of the functions available in SageMath (described for using it in a Terminal) or see e.g. this guide on how to use the Jupyter notebook.
SageMathCell
If you have an internet connection and want to perform a short computation, you can go to the website of SageMathCell. Enter the lines of code you want to run and click a button to see the result. Or you just try it out directly below!
Cocalc
For longer computations and projects, you can got to the website of Cocalc and create a free account. Then you can create a new project, and add either a Terminal or a Jupyter notebook as a new file (or upload an existing notebook). Use them as explained above.
Local SageMath installation
The most convenient way to work with SageMath is to install it on your computer. You can have a look at the official installation guide. Here is the short version for the most important operating systems:
- Linux If you are using Linux, you are probably used to multiple-step guides involving use of a console, so you should just follow the section of the installation guide above. Or maybe you are working on a university computer, where SageMath is already installed. In either case, open a terminal and type
sage
to run SageMath in a console, or sage -n jupyter
to work with a Jupyter notebook in your browser.
- Windows
As described in the official guide, a nice way to use SageMath on a modern Windows machine is via the Windows Subsystem for Linux (WSL). To install this, open a command prompt in Administrator mode and type
wsl --install
to install WSL. Then restart your computer, open the new App "Ubuntu" (not the command prompt from above!) and type sudo apt update; sudo apt install sagemath
in the console that opens. Now you should be able to use the console version of SageMath in the Ubuntu-App. For using the notebook: if you type sage -n jupyter
in the Ubuntu-console, it will print a bunch of lines, with the last ones approximately looking as follows:
To access the notebook, open this file in a browser:
file:///home/YourUserName/.local/share/jupyter/runtime/nbserver-7740-open.html
Or copy and paste one of these URLs:
http://localhost:8888/?token=5a440943af44c43167aa79386026b15d5068d00c674c1fc8
or http://127.0.0.1:8888/?token=5a440943af44c43167aa79386026b15d5068d00c674c1fc8
Then you can copy-paste the http-link into a browser to start working in Jupyter. To avoid this step, you can make a change to an appropriate configuration file (again see the official guide).
Alternatively, go to the GitHub release page of SageMath for Windows to download the latest SageMath-XX-Installer-YY.exe and run it. This should install SageMath on your computer, and you can run the program "SageMath X.Y" to use it in a console, or run "SageMath X.Y Notebook" to access a Jupyter notebook.
- MacOS Installing SageMath here can be slightly tricky, but many people had good experiences with this inofficial guide for installation and usage of SageMath.
If you still have some older version of SageMath installed on your computer, note that starting with Version 9.0 it switched from Python 2 to Python 3 so some older code might no longer work as expected.
For students of my course
SageMath will (hopefully) be installed on the computers of the Mathematical Institute once the semester starts. Thus you can log onto them (or use ThinLinc on your own computer) and open the program Terminal. Then you can type sage-9.4
to start SageMath in the terminal, or use sage-9.4 -n jupyter --browser=google-chrome
to open a Jupyter notebook. We will mostly use the second option in our course. You should then navigate with the Jupyter notebook to the place where you saved the files for the lecture (like "01 Introduction.ipynb") and open them with a click.
Note that in the process above you will be asked for your password approximately \(N\) times (for \(N \to \infty\)) and probably you will always use your standard password for logging into the computers of the Mathematical Institute.
LaTeX formulas on this site powered by MathJax
Back to Johannes Schmitt's homepage