Easy Sagemath setup

I recently started using SageMath and it’s a game changer! 🔥 Prototyping simple or more complex mathematical thoughts has never been this smooth!

I work daily on both an ARM MacBook and an x64 Ubuntu machine, setting it up properly on both was a bit of a hassle at first. After some trial and error, I found the simplest solution: running SageMath in Docker.

The official Docker image, sagemath/sagemath, works flawlessly. If you’re on an ARM Mac, be sure to add the --platform linux/amd64 flag when pulling the image:

docker pull --platform linux/amd64 sagemath/sagemath

Once downloaded, you can either launch the Sage REPL or run a script directly:

# on ARM Mac
docker run -it --rm --platform linux/amd64 sagemath/sagemath
docker run --rm --platform linux/amd64 -v $(pwd):/app -w /app sagemath/sagemath 'sage myscript.sage'

# not on mac
docker run -it --rm sagemath/sagemath
docker run --rm -v $(pwd):/app -w /app sagemath/sagemath 'sage myscript.sage'

Small change on Linux

Recently, I noticed a small change on Linux that required me to run the script as root. You might not need this, but if you run into permission issues, try using sudo:

docker run --rm -v $(pwd):/app -w /app sagemath/sagemath 'sudo sage myscript.sage'

That’s it! 🚀 Now you have a fully functional SageMath setup with zero headaches.

If you’re a beginner and still running into issues, feel free to reach out on Twitter @0xteddav, I’d be happy to help! ❤️

Written on February 24, 2025