Archive

Archive for the ‘Linux’ Category

Compiling Sage on Linux and Mac OS X

14 November 2010 4 comments

Compiling Sage can be a difficult process. The difficulty is compounded by the many versions of the GNU/Linux and Mac OS X operating systems. In this post, I don’t want to cover every possible ways of compiling Sage on each operating system. My goal here is to provide a general overview of how to compile Sage on Ubuntu 10.10 and Mac OS X 10.6.x.

Ubuntu 10.10

For Linux, it should be sufficient to explain how to compile Sage under Ubuntu. The following commands were tested under Ubuntu 10.10. First, make sure you have the necessary tools for compiling Sage. To install these tools, execute the following command from a terminal window:

$ sudo apt-get install build-essential gfortran m4 readline-common libreadline-dev

Suppose you have downloaded the Sage source distribution and it is saved as the file named sage-x.y.z.tar. The file extension “.tar” signifies that sage-x.y.z.tar is a tar archive, also called a tar file or a tarball. To compile Sage, you need to launch a terminal window, extract the Sage source files from the tarball, and use development tools that come with Ubuntu to compile Sage. Suppose the Sage source tarball is located at

/home/username/sage-x.y.z.tar

where “username” is your username, the one you use to login to your Ubuntu system; you should replace “username” your actual username. Say you want to compile Sage under the directory /home/username/. From your terminal window, navigate to your home directory and extract the source tarball:

$ cd
$ tar -xf sage-x.y.z.tar

which will produce a directory called

/home/username/sage-x.y.z/

that contains all the packages that are distributed with the Sage source distribution. You are now ready to compile Sage as contained under the latter directory. Note that you can rename the latter directory to, say, /home/username/mysage/ as follows:

$ mv sage-x.y.z mysage

If you have a directory, say, /home/username/bin/ and you want to extract the Sage source tarball to that directory, you can do so as follows:

$ tar -xf sage-x.y.z.tar -C /home/username/bin

Here, it is assumed that you want to compile the Sage source as contained under

/home/username/sage-x.y.z/

This top-level directory is usually referred to as SAGE_ROOT and is where the compiled version of Sage resides. The next step is to navigate to the latter directory and start the automated compilation process:

$ cd /home/username/sage-x.y.z/
$ make

Usually, that is all you need to do. The rest of the compilation process is non-interactive and takes at most a few hours, depending on your system.

Note that compiling Sage is very taxing on your system’s resources, i.e. CPU, RAM, disk space, and so on. Make sure you have sufficient system resources; for example, you could close all running applications and ensure you have at least 2 GB of free disk space for Sage. Furthermore, the compilation process can take from a dozen or so minutes to a few hours, depending on your system’s hardware and how you customized the compilation process. By default, the compilation process uses one thread to compile Sage, which means that every component is compiled one after the other, i.e. serial compilation. Serial compilation of Sage is known to take up to an hour or more to complete.

On a multi-core or multi-CPU system, the compilation process can be parallelized. This means that many components of Sage can be compiled in parallel, hence reducing the time it takes for the compilation process to complete. The general steps to compile Sage in parallel are as follows. Determine the number of cores on your system and decide on how many threads you want to devote to a parallel compilation of Sage. On Ubuntu, detailed information about your system’s CPU is contained in the file

/proc/cpuinfo

Read through that file to determine the number of cores on your system. Say your system has two cores and you want to use two threads for compiling Sage in parallel. Then the necessary setup to compile Sage with two threads is:

$ SAGE_PARALLEL_SPKG_BUILD="yes"; export SAGE_PARALLEL_SPKG_BUILD
$ MAKE="make -j2"; export MAKE
$ make

This should initiate the process of compiling Sage in parallel. If your system allows for compiling Sage with more threads, e.g. 4 or 8 threads, then change “-j2” to “-j4” or “-j8” accordingly.

Once all components of Sage are successfully compiled, the compilation process will automatically build the HTML version of the Sage standard documentation. This documentation includes a tutorial, an FAQ, a collection of thematic tutorials, a reference manual, an installation guide, among other documents. Building the HTML version of the Sage standard documentation does not require \LaTeX. However, for best results, it is recommended that you have \LaTeX installed on your system. Furthermore, \LaTeX is a prerequisite for building the PDF version of the Sage standard documentation. The following command installs the full \LaTeX distribution that comes with Ubuntu:

$ sudo apt-get install texlive-full

This will also install necessary tools for building both the HTML and PDF versions of the Sage documentation. To manually build the HTML version of the documentation, do the following from within the SAGE_ROOT directory:

$ ./sage -docbuild all html  # or
$ ./sage -docbuild --no-pdf-links all html

To build the PDF version of the documentation, do

$ ./sage -docbuild all pdf

For further options to customize your build of the Sage standard documentation, see the output of the following command:

$ ./sage -docbuild

You can also download the documentation from

http://www.sagemath.org/help.html

or view it online at

http://www.sagemath.org/doc

To customize the compilation process to your particular needs, refer to the file

SAGE_ROOT/Makefile

Once the compilation process completes, there is no separate installation process for your newly compiled Sage. You can think of Sage as being compiled and installed under SAGE_ROOT. To begin using your freshly compiled version of Sage, navigate to SAGE_ROOT and launch Sage as follows:

$ cd /home/username/sage-x.y.z/
$ ./sage

Mac OS X 10.6.x

For Mac OS X, most of the prerequisites for compiling Sage are bundled with XCode, which is freely available from Apple’s website. Install XCode as directed by Apple’s installation instructions and download the latest Sage stable source distribution from the Sage website. If you have XCode installed on your system, then the following commands should not result in any errors:

$ which gcc
/usr/bin/gcc
$ which g++
/usr/bin/g++
$ which make
/usr/bin/make
$ which m4
/usr/bin/m4
$ which perl
/usr/bin/perl
$ which tar
/usr/bin/tar
$ which ranlib
/usr/bin/ranlib

Suppose you have downloaded the Sage source distribution and it is saved as the file named sage-x.y.z.tar. The file extension “.tar” signifies that sage-x.y.z.tar is a tar archive, also called a tar file or a tarball. To compile Sage, you need to launch a terminal window, extract the Sage source files from the tarball, and use tools that come with XCode to compile Sage. A terminal window or a console is usually launched when you run the program Terminal, which is found at

/Applications/Utilities/Terminal.app

under Mac OS X 10.4.x. For Mac OS X 10.5.x and 10.6.x, use the application finder to locate Terminal and then launch Terminal. Suppose the Sage source tarball is located at

/Users/username/sage-x.y.z.tar

where “username” is your username, the one you use to login to your Mac OS X system; replace “username” with your actual username. Say you want to compile Sage under the directory /Users/username/. From your terminal window, navigate to your home directory and extract the source tarball:

$ cd
$ tar -xf sage-x.y.z.tar

which will produce a directory called

/Users/username/sage-x.y.z/

that contains all the packages that are distributed with the Sage source distribution. You are now ready to compile Sage as contained under the latter directory. Note that you can rename the latter directory to, say, /Users/username/mysage/ as follows:

$ mv sage-x.y.z mysage

If you have a directory, say, /Users/username/bin/ and you want to extract the Sage source tarball to that directory, you can do so as follows:

$ tar -xf sage-x.y.z.tar -C /Users/username/bin

Here, it is assumed that you want to compile the Sage source as contained under

/Users/username/sage-x.y.z/

This top-level directory is usually referred to as SAGE_ROOT and is where the compiled version of Sage resides. The next step is to navigate to the latter directory and start the automated compilation process:

$ cd /Users/username/sage-x.y.z/
$ make

Usually, that is all you need to do. The rest of the compilation process is non-interactive and takes at most a few hours, depending on your system.

Note that compiling Sage is very taxing on your system’s resources, i.e. CPU, RAM, disk space, and so on. Make sure you have sufficient system resources; for example, you could close all running applications and ensure you have at least 2 GB of free disk space for Sage. Furthermore, the compilation process can take from a dozen or so minutes to a few hours, depending on your system’s hardware and how you customized the compilation process. By default, the compilation process uses one thread to compile Sage, which means that every component is compiled one after the other, i.e. serial compilation. Serial compilation of Sage is known to take up to an hour or more to complete.

On a multi-core or multi-CPU system, the compilation process can be parallelized. This means that many components of Sage can be compiled in parallel, hence reducing the time it takes for the compilation process to complete. The general steps to compile Sage in parallel are as follows. Determine the number of cores on your system and decide on how many threads you want to devote to a parallel compilation of Sage. On Mac OS X, detailed information about your system’s hardware is obtained via the command

$ system_profiler

Say your system has two cores and you want to use two threads for compiling Sage in parallel. Then the necessary setup to compile Sage with two threads is:

$ SAGE_PARALLEL_SPKG_BUILD="yes"; export SAGE_PARALLEL_SPKG_BUILD
$ MAKE="make -j2"; export MAKE
$ make

This should initiate the process of compiling Sage in parallel. If your system allows for compiling Sage with more threads, e.g. 4 or 8 threads, then change “-j2” to “-j4” or “-j8” accordingly.

Once all components of Sage are successfully compiled, the compilation process will automatically build the HTML version of the Sage standard documentation. This documentation includes a tutorial, an FAQ, a collection of thematic tutorials, a reference manual, an installation guide, among other documents. Building the HTML version of the Sage standard documentation does not require \LaTeX. However, for best results, it is recommended that you have \LaTeX installed on your system. Furthermore, \LaTeX is a prerequisite for building the PDF version of the Sage standard documentation. To manually build the HTML version of the documentation, do the following from within the SAGE_ROOT directory:

$ ./sage -docbuild all html  # or
$ ./sage -docbuild --no-pdf-links all html

To build the PDF version of the documentation, do

$ ./sage -docbuild all pdf

For further options to customize your build of the Sage standard documentation, see the output of the following command:

$ ./sage -docbuild

You can also download the documentation from

http://www.sagemath.org/help.html

or view it online at

http://www.sagemath.org/doc

To customize the compilation process to your particular needs, refer to the file

SAGE_ROOT/Makefile

Once the compilation process completes, there is no separate installation process for your newly compiled Sage. You can think of Sage as being compiled and installed under SAGE_ROOT. To begin using your freshly compiled version of Sage, navigate to SAGE_ROOT and launch Sage as follows:

$ cd /Users/username/sage-x.y.z/
$ ./sage
Advertisements

Portable shell scripting

26 September 2010 1 comment

Add users to a cluster

15 September 2010 Leave a comment

Problem

You need to add a new user to a cluster of computers that uses Network Information Service (NIS). How do you add the user and get all cluster nodes to recognise that user?

Solution

See Chapter 15 NIS: Network Information Service of the book SuSE Linux Internals for more information on using NIS.

  1. Identify which machines in the cluster is a NIS server and login to that machine.
  2. Use the command /usr/sbin/adduser to create an account for the new user with a default password.
  3. Navigate to /var/yp and issue the command make with the necessary credential.
  4. Login as the new user and change her default password to another default password. You can use the program apg to generate strong random default passwords. See this page in the Ubuntu Community Documentation for more information.
  5. Send the new user her login credentials and inform her to change her default password during her first login session.

Compiling and installing MPlayer

11 September 2010 Leave a comment

MPlayer is a program for playing music and video files, and much more. I occasionally compile MPlayer twice or three times a year. Below are the steps I use, collected together so I don’t lose them.

  1. Download the binary codecs. I usually choose the latest version of all codecs as packaged in the tarball all-20*. As of this writing, the latest comprehensive binary codecs package for Linux is all-20100303.tar.bz2.
  2. Download the MPlayer source from the SVN repository:
    $ svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
    
  3. As root, install the binary codecs:
    $ sudo mkdir /usr/local/lib/codecs/
    $ sudo cp -rf all-20100303/* /usr/local/lib/codecs/
    $ sudo ln -s /usr/local/lib/codecs /usr/lib/win32
    
  4. As a normal user, cd into the top-level directory of the MPlayer source distribution and configure MPlayer:
    $ ./configure --enable-largefiles --enable-menu --prefix=$HOME/usr
    
  5. Now compile and install:
    $ make
    $ make install
    

Haskell mode spews junk on first load

9 September 2010 Leave a comment

I’m using Haskell mode version 2.8.0 with Emacs 23.1.1 under Ubuntu 10.04.1 LTS. After loading a Haskell file, I would get the following garbage:

#[nil "\300C\207"
      [t]
      2]

Here’s what it looks like:

Acting on a tip from the ArchLinux community, I grep’d through all the Emacs Lisp files in the source distribution of Haskell mode 2.8.0 and found that the garbage in question is output by the following function in haskell-mode.el:

(eval-when-compile
  ;; Emacs 21 defines `values' as a (run-time) alias for list.                  
  ;; Don't maerge this with the pervious clause.                                
  (if (string-match "values"
                    (pp (byte-compile (lambda () (values t)))))
      (defsubst values (&rest values)
        values)))

The culprit is the line

(pp (byte-compile (lambda () (values t)))))

I commented out that whole function and the junk is no longer seen when I first load a Haskell file.

Debian 5.0 Lenny official beta

4 October 2008 2 comments

For the last few hours today, I’ve been playing around with Debian 5.0 Lenny (official beta). The installation process has improved greatly since my last installation back in 2006, especially the graphical installation option. The graphical installer is quite intuitive — at least to someone with some experience installing various Linux distributions.

Booting the Debian 5.0 DVD.

Booting the Debian 5.0 Lenny (official beta) DVD.

Another nice feature about the graphical installer is that it allows you to produce screenshots while you’re installing. The option to produce screenshots is marked with a button called “Screenshot”. All screen captures produced are saved to your disk in

/var/log/installer/

or thereabout. This is a good thing because it provides you with visuals to use if you’re writing tutorials on how to install various distros, in this case, Debian Lenny. On the other hand, the site linuxscreenshots.org provides loads of screenshots for such a purpose.

I have a box for everyday work and development, and another box for testing purposes. This doesn’t mean that I exclusively use the testing box for testing only. I do use it for everyday work as well. It is on the testing machine that I installed Debian 5.0 official beta, configured to dual boot with Fedora 9.

Partitioning the disk for Debian and Fedora to co-exist.

Partitioning the disk for Debian and Fedora to co-exist.

Installing the official beta version of Debian Lenny took less than an hour. That’s because in the “Software selection” screen, I only selected the options “Desktop environment” and “Standard system”. Plus the hardware I use is relatively fast, although it’s not a multi-core machine.

Selecting software for my Debian box.

Selecting software for my Debian box.

After successfully installing using the graphical installer, I was able to dual boot into both Fedora and my new Debian distro. Here’s a screenshot of my “Lenny” Gnome desktop:

Gnome desktop under Debian Lenny.

Gnome desktop under Debian Lenny official beta.

More screenshots taken during the installation can be found in my web album.

Software Freedom Day 2008

28 September 2008 2 comments

The 2008 Software Freedom Day event in Melbourne, Australia was held at The Hub@Docklands. The event started off with a breakfast for volunteers

Free breakfast for volunteers.

Free breakfast for volunteers.

followed by the setting up of the venue itself

Setting up the venue.

Setting up the venue.

A number of people from various organizations delivered talks during the day. Among them include

I gave a mini-talk on computer algebra systems in maths education

A mini-talk on computer algebra systems, in particular Sage.

A mini-talk on computer algebra systems, in particular Sage. Thanks to Peter Baker for this shot.

More photos taken during the day can be found at Picasaweb or Flickr. James Collier has written about the event, commenting on its strengths and a number of shortcomings during the day. Overall, I think the event went pretty well for what it’s meant to do.