Here’s how I got a fully featured Sage Math install on my system. I did this because I wanted to run on windows, and still be able to install packages, which isn’t possible with the precompiled binary.
- Enable hardware assisted virtualization.
- Set up WSL (Windows Subsystem for Linux)
- Install Linux into WSL
- Download and compile Sage
- Configure JupyterLab
- Make it easy to start from windows
Enable hardware assisted virtualization
WSL requires that your system supports hardware assisted virtualization (which pretty much all modern systems), there are 3 things that you need to get it working:
- The CPU must support it
- The motherboard must support it.
- You need to enable it in the EFI (or BIOS)
This article takes you through getting everything sorted out:
Set up WSL 2
Follow this guide: https://docs.microsoft.com/en-us/windows/wsl/install-win10
Install and configure Linux:
- Go to the Microsoft store and install Ubuntu.
Note: If you already have Ubuntu installed, I’d recommend you follow these instructions to set up a separate, clean install for sage: https://hfakhraei.github.io/Install-multiple-instance-of-same-Linux-Distribution-on-WSL
- Start Ubuntu from the start menu. A command window should pop up.
- Run these commands to update Ubuntu:
sudo apt update sudo apt upgrade
- Reboot by going (in Windows) to Services and restarting the LxssManager. You can also shut down all running WSL instances using the command
wsl --shutdownin the Windows command prompt or Powershell.
- If necessary upgrade to the latest release: https://linuxconfig.org/how-to-upgrade-ubuntu-to-20-10
Set up Sage
These instructions are a simplified version of the official documentation: https://doc.sagemath.org/html/en/installation/source.html
- Start Ubuntu – All the commands in this section should be run on the Ubuntu installation.
- Install the packages we need to have ready in advance:
sudo apt install bc binutils bzip2 ca-certificates cliquer cmake coinor-cbc coinor-libcbc-dev curl default-jdk dvipng eclib-tools fflas-ffpack ffmpeg flintqs g++ gcc gfan gfortran git glpk-utils gmp-ecm imagemagick latexmk lcalc libatomic-ops-dev libavdevice-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 libfile-slurp-perl libflint-arb-dev libflint-dev libfreetype6-dev libgc-dev libgd-dev libgf2x-dev libgiac-dev libgivaro-dev libglpk-dev libgmp-dev libgsl-dev libiml-dev libisl-dev libjson-perl liblfunction-dev liblrcalc-dev liblzma-dev libm4rie-dev libmongodb-perl libmpc-dev libmpfi-dev libmpfr-dev libnauty-dev libncurses5-dev libntl-dev libopenblas-dev libpari-dev libpcre3-dev libperl-dev libplanarity-dev libppl-dev libpython3-dev libreadline-dev librw-dev libsqlite3-dev libssl-dev libsuitesparse-dev libsvg-perl libsymmetrica2-dev libterm-readkey-perl libterm-readline-gnu-perl libxml2-dev libxml-libxslt-perl libxml-writer-perl libz-dev libzmq3-dev libzn-poly-dev m4 make nauty ninja-build openssl palp pandoc pari-doc pari-elldata pari-galdata pari-galpol pari-gp2c pari-seadata patch perl pkg-config planarity ppl-dev python3 python3-distutils r-base-dev r-cran-lattice sqlite3 sympow tachyon tar texlive texlive-xetex xcas xz-utils yasm
- Download and extract the source tarball into a subfolder of your home directory
cd ~ wget http://www.mirrorservice.org/sites/www.sagemath.org/src/sage-9.2.tar.gz tar xvf sage-9.2.tar.gz
- Start building
cd sage-9.2/ ./configure make
This will take a long time (3 hours on my system)
- Test sage
You should get a prompt that looks like this:
┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 9.2, Release Date: 2020-10-24 │ │ Using Python 3.8.6. Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ sage:
exitand press enter to leave.
- Make the command available from anywhere on this ubuntu system – edit ~/.bashrc and add this line:
- Close ubuntu then reopen it.
- Try typing
sageand verify that it starts.
- Install Jupyter Lab and it’s extras:
sage -i jupyterlab_widgets
This also involves compliation from source, so will take a while.
- When it’s done, try starting the jupyterlab notebook like this:
sage --notebook jupyterlab
You might notice a problem – the list of files only includes those on your linux machine – you probably want the ones on your windows computer. You can do this by navigating to where the windows files are mounted in linux.
- Try it (fill in your windows username instead of the square brackets):
cd /mnt/c/Documents\ and\ Settings\[your windows username] sage --notebook jupyterlab
The list of files should now be the ones in that folder on your windows machine.
- Lets wrap this all in a script for convenience – Create a file called ~/
sage_nb.shand put these lines into it:
#!/bin/bash cd /mnt/c/Documents\ and\ Settings/[your windows username] /home/[your linux username]/sage-9.2/sage --notebook jupyterlab
- We need to make it executable – ie. so linux will run this file like it would run a program:
chmod ug+x sage_nb.sh
- Now go back to your home directory and try it again:
cd ~ ./sage_nb.sh
The JupyterLab server should start, showing your windows files in the browser.
Create windows shortcut
This is a final nicety that lets you start the JupyterLab server in one click:
- Open Windows explorer, and type %APPDATA%\Microsoft\Windows\Start Menu\Programs
- Make a copy of any of the program icons – we’ll customise it to do what we want
- Right-click, and choose properties.
- On the General tab:
- Change the name to whatever you want.
- On the Shortcut tab:
- Change Target to:
ubuntu.exe run ~/sage_nb.sh
- Change Start in to:
- Change Run to: Minimised
- Change the icon if you want – there are plenty of pieces of software that can create a
.icoicon file one from an image file.
- Change Target to:
- Now hit the start button or key and type the name you gave it. it should appear in the list, and should load the server and fire up your browser when you click on it.
This is what I used when I wrote this post – you might get different results if your versions are significantly different.
- Windows 10 Pro Version 2004 (OS Build 19041.264)
- Ubuntu 20.10 (Originally installed 20.04 as 20.10 was not available in the Windows Store)
- Sage 9.2