CoCalc Shared FilesInstall-GAP-in-CoCalc-project.mdOpen in CoCalc with one click!
Authors: Pedro A. Garcia, Sebastian Gutsche, Samuel Lelièvre
Views : 81
Description: Install GAP 4.10.0 in CoCalc project

Install GAP 4.10.0 in a CoCalc project

Author: Samuel Lelièvre

Date: 2019-01-15

License: CC0


Instructions on how to build GAP in a CoCalc project.

(Should go roughly the same in any Linux or macOS system.)

Install GAP 4.10.0 following instructions on the GAP website

See instructions at

Note in particular that the path to the GAP directory should not contain spaces.

For a system-wide install, note the extra step in the file:

  (If you unpack the archive as root user under Unix, make sure that you
  issue the command `umask 022` before, to ensure that users will have
  permissions to read the files.)

System-wide installation of GAP in CoCalc is discussed at

Download the tarball

This corresponds to "section 2: getting the archive" of the file.

Done here using curl; one could alternatively use wget.

In a CoCalc project without internet access, one could

We first set our working directory to our home (change if needed).


The tarball is at so we set:

$ VERSION='gap-4.10.0'
$ TARBALL=$VERSION'.tar.bz2'

and we download using curl (we could also use wget):

$ curl -C - --retry 99 -o $TARBALL $REMOTE/$TARBALL

Check the sha256 hash

This step is omitted in section 2 of the file, but it is good practice.

We compute the sha256 of the tarball, and check that it matches the one on the download page; for GAP 4.10.0, it should match 2dc71364b7418d16f8b99ca914971996fa4416294fa3ae8fb336c873c946abb6.

$ sha256sum $TARBALL

Unpack the tarball

This corresponds to "section 3: unpacking" of the file.

Warning: this will erase the $GAPDIR directory if already present.

$ tar xjf $TARBALL
$ ls $WORKDIR | grep -E "^gap"

Configure and make

This corresponds to "section 4: compilation" of the file.

Check if the MAKE environment variable is set:

$ echo $MAKE

Optionally, set the MAKE environment variable

$ export MAKE='make -j4'

Configure and make

$ cd $GAPDIR
$ ./configure && make

Install packages

This corresponds to "section 7: packages" of the file.

We do this before testing the installation.

$ cd $GAPDIR/pkg
$ ../bin/

Check the content of the pkg directory.

$ ls $GAPDIR/pkg

Test the installation

This corresponds to "section 2: testing the installation" of the file.

$ ls $GAPDIR
$ ls $GAPDIR/bin
$ TEST='Read(Filename(DirectoriesLibrary("tst"), "testinstall.g"));'
$ echo $TEST > test_gap.g
$ $GAPDIR/bin/ test_gap.g

Optional: symbolic link to this version of GAP

This is so that typing gap in a terminal will launch this GAP rather than the system-wide installed GAP.

$ mkdir -p $HOME/bin
$ ln -s $GAPDIR/bin/ $HOME/bin
$ which gap

Install the GAP Jupyter kernel

Following the installation guide in the manual for the GAP package "JupyterKernel".

All system prerequisites are there; all prerequisite GAP packages are there and those that need compiling have been compiled.

The JupyterKernel GAP package itself is also present.

So it is just a matter of making it known to Jupyter, by doing:

$ cd $GAPDIR/pkg/JupyterKernel-1.0
$ python3 install --user
Installing jupyter kernel spec
Installing nbextension for syntax hilighting

Then the list of available kernels contains GAP-4:

$ jupyter kernelspec list
Available kernels:
  gap-4               /home/user/.local/share/jupyter/kernels/gap-4

and we can check the content of the kernel.json for that:

$ cat /home/user/.local/share/jupyter/kernels/gap-4/kernel.json
{"argv": ["jupyter-kernel-gap", "{connection_file}"], "display_name": "GAP 4", "language": "gap", "codemirror_mode": "gap", "env": {"PS1": "$"}, "interrupt_mode": "message"}

The kernel does not seem to work.

Tried modifying /home/user/.local/share/jupyter/kernels/gap-4/kernel.json so it reads

{"argv": ["jupyter-kernel-gap", "{connection_file}"], "display_name": "GAP 4", "language": "gap", "codemirror_mode": "gap", "env": {"JUPYTER_GAP_EXECUTABLE": "gap"}, "interrupt_mode": "message"}


{"argv": ["jupyter-kernel-gap", "{connection_file}"], "display_name": "GAP 4", "language": "gap", "codemirror_mode": "gap", "env": {"JUPYTER_GAP_EXECUTABLE": "gap -r -A"}, "interrupt_mode": "message"}


{"argv": ["/home/user/gap-4.10.0/pkg/JupyterKernel-1.0/jupyter-kernel-gap", "{connection_file}"], "display_name": "GAP 4", "language": "gap", "codemirror_mode": "gap", "env": {"JUPYTER_GAP_EXECUTABLE": "/home/user/bin/gap"}, "interrupt_mode": "message"}

Tried modifying the PATH in .bashrc.

Tried adding this line in .bashrc:





export JUPYTER_GAP_EXECUTABLE="/home/user/bin/gap -r -A"

Tried installing JupyterKernel 1.1:

$ cd $GAPDIR/pkg
$ curl -L -O
$ tar xf JupyterKernel-1.1.tar.gz
$ cd JupyterKernel-1.1
$ python3 install --user

No luck getting it to work.

At some point I had managed to reach a state like the one illustrated by the screenshot at but then kept tinkering and could never reproduce that.

In that state, you could execute a cell, and would have to interrupt with ctrl-C, which would cause the output to be displayed, followed by a similar error message to that in the screenshot, involving ZeroMQ communications.

Then after all that, tried in Plain Jupyter and JupyterLab, and it works fine there!

It's just not working in CoCalc-Jupyter.

Note that contrary to the previous GAP Jupyter kernel based on pexpect and Python, and now deprecated (see, this new kernel is implemented in the GAP language.

Maybe that gives CoCalc-Jupyter trouble...