Install Sage 5.3 on Debian Squeeze + InitScript

One virtual machine on our private network runs an instance of Sage, which is an open-source alternative to Matlab, Maple or Mathematica. In fact it’s a very powerful framwork using Python as primary language for describing (for example) mathematical, algorithmic or topological problems. It comes handy for practices at university in algorithms or cryptography courses and there’s already a lot of sage related documentation and material outthere.
Still, there’s one problem with distribution packaging to solve to make Sage available to a broader audience. Because Sage consists of various Python libraries and toolkits, which are packed with Sage, it’s difficult to maintain and distribute it, especially if you don’t want to serve one monolithic program instead of seperating the libs as dependency.
Nevertheless, installing Sage (even as a daemon) is easy and here’s a short how-to for Debian Squeeze:

useradd sage
mkdir /home/sage /usr/local/sage # Home-Dir contains all preferences and project-files of Sage
chown -R sage:sage /usr/local/sage /home/sage
su sage
cd /usr/local/sage
aria2c ""
tar xvf sage-5.3.tar --strip-components=1
export MAKE="make -j4"
mkdir /var/log/sage
chown -R sage:sage /var/log/sage
./sage -upgrade
sage: optional_packages()
sage: install_package('openmpi-XXX')
sage: install_package('mpi4py-YYY')

# Provides:          sage
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts sage-mathematics server
# Description:       starts sage-mathematics server using start-stop-daemon

# configuration
SAGE_OPTS="-notebook interface= port=8081"
# commands

sage_start() {
        echo "Starting Sage..."
        start-stop-daemon --start --background --chuid "$USER" --chdir "$SAGE_HOME" --exec $SAGE_HOME/sage -- $SAGE_OPTS # -- $SAGE_LOG
sage_stop() {
        echo "Stopping Sage..."
        kill `ls "/home/$USER/.sage/temp/application/"`
case $1 in
                sleep 5
                echo "Use: $0 {start|stop|restart}"
                exit 1
exit 0

Adjust the variable SAGE_OPTS for the parameters passed to Sage. In most cases “-notebook” should be enough, if you only want to use Sage locally. The sage_stop function is a bit hacky but it works for me.
To autostart the daemon at boot time, run:

chmod +x /etc/init.d/sage
update-rc.d sage defaults 95
/etc/init.d/sage start

You can access Sage with your browser (considering default settings) on

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

* Checkbox GDPR is required


I agree

Bye bye Play Store! Mirroring Play Store Apks to private F-Droid repo

This small tutorial will show you how to setup your own F-Droid repository containing automatically mirrored Play Store apps. Using this private repo, you don’t have to relay on Google Play Store or third party stores anymore to keep non-free apps up-to-date. All you need to have is a Linux …

Ebook reader app for Nextcloud

Because of lack of altenatives I decided to write a small ebook reader plugin for Nextcloud. The task of creating such an app was quite easy: I just forked the files_pdfviewer extension and replaced PDF.js with the Epub.js library. In the app template file, I used the reference ebook reader …

Hacking replay gain audio normalization into Jellyfin

There is already a feature request for audio normalization in Jellyfin media server. This is important if you want to listen to your music collection while always having the same loudness level. Usually, in different recordings or music genres some tracks are louder and others are more quiet. The standard …