You can install Octave from source without any GUI stuff.
$ wget -c ftp://ftp.gnu.org/gnu/octave/octave-4.2.1.tar.xz
$ tar -xf octave-4.2.1.tar.gz
(or newer version, depending on what you want)
$ cd octave-4.2.1/
$ ./configure --without-java
The configure script will likely give you a bunch of errors and/or warnings because of missing dependencies. In fact Octave is quite forgiving with missing libraries, but a few are obviously required or at least highly advisable to have. I would at least
$ sudo apt-get install gfortran libfftw3-dev libfltk1.3-dev libarpack2-dev libqrupdate-dev libreadline-dev texinfo
./configure --without-java. It may still give errors, depending on what you have already installed on your system. The standard rule is: for e.g.
configure: WARNING: FFTW3 library not found.
fetch the library with
sudo apt-get install libfftw3-dev.
Once the configure script runs with no warnings except those relating to GUI, Java, audio, or logos, you can start the build:
This will take some time. If you're in a hurry and/or have some CPU cores to spend, use
make -j4 for quadruply-parallel compilation.
Once this is done, check that everything works with e.g.
GNU Octave, version 4.0.0
Copyright (C) 2015 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. For details, type 'warranty'.
Octave was configured for "x86_64-unknown-linux-gnu".
Additional information about Octave is available at http://www.octave.org.
Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html
Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.
octave:1> [1 2 3; 4 5 6]
1 2 3
4 5 6
octave:2> [1 2 3; 4 5 6] \ [1; 0]
octave:3> svd([1 2 3; 4 5 6])
If something doesn't work yet, you may wish to install more libraries, then configure and
$ make again. (Perhaps you first need to
$ make clean so it actually builds anew, not sure about this.)
If it works to your satisfaction, finally bake the install to your system:
$ sudo make install