Friday, March 13, 2015

Installing OctaveForge Packages

I recently had to install Octave's version of Matlab's Optimization Toolbox to perform a nonlinear least-squares curve fit. I thought I'd archive the process here, for future use.

I am doing this on a Ubuntu Desktop, but the process ought to be similar on other Linux machines.

Installing Packages

1. Install the package "liboctave-dev" using the GUI Software Center, Synaptic Package manager, or the command line as:
sudo apt-get install liboctave-dev
2. Go to Octave-Forge site to download the "tar-gz" file for the package you want to install. It tells you how up-to-date your Octave has to be, and what other packages you need.
Dependencies: Octave (>= 3.6.0) struct (>= 1.0.10)
I downloaded the struct-1.0.11.tar.gz and optim-1.4.1.tar.gz files.

3. Open an Octave session in the location where you saved the zipped files. At the prompt type:

> pkg install struct-1.0.11.tar.gz
> pkg install optim-1.4.1.tar.gz

If there are no errors, then the package is successfully installed.

UPDATE October 2018: With a newer Octave installation [ > 3.4.0], you can merge the download and install steps by a command like:

> pkg install -forge struct

It does the downloading, installing, and cleaning up for you.

Loading Packages

When you want to use a function from a package in an Octave program, you first have to load the package name (not the filename) into the session.

> pkg load optim # (note optim, not optim-1.4.1.tar.gz)

To unload a package

> pkg unload optim

Miscellaneous

Q: How do I find out what packages I have?
A: > pkg list

Package Name  | Version | Installation directory
--------------+---------+-----------------------
       optim  |   1.4.1 | /home/sachins/octave/optim-1.4.1
      struct  |  1.0.11 | /home/sachins/octave/struct-1.0.11


Q: How do I update installed packages?
A: If you have an internet connection, you can update packages from an Octave prompt by:
> pkg update

Q: Where are the installed packages?
A: By default they are stored in the ~/octave/ directory. If not present, it is created the first time you install an Octave package.

No comments:

Post a Comment