CS 2213: Advanced Programming

The University of Texas at San Antonio
Spring Semester, 2009

Useful Tips for Linux and C Programming

Making vi the Default Editor

On Ubuntu installs, including the department machines, the default editor is nano instead of vi. This is the editor that will normally get used when you run svn commit. If you'd rather have vi, there are a couple options for going about this:

  1. Edit ~/.subversion/config and change the line:
    # editor-cmd = editor (vi, emacs, notepad, etc.)
    
    to
    editor-cmd = vi
    
    "#" is usually the comment marker (like "//" in C99, C++, and Java) in UNIX shells and config files. This will change the editor for subversion only.
  2. If you want to use vi as your default editor for any normal UNIX/GNU program that needs an editor, you can set the EDITOR environment variable.

    • On tcsh (which is the shell you get when you login on the department machines), this can be accomplished by using the shell builtin command setenv EDITOR vi before running svn. The environment variables get reset each time you login; you can make this change permanent by adding the line:

      setenv EDITOR vi
      

      to your ~/.login file. (If ~/.login doesn't exist, you can create one containing just the setenv command.)

    • For the bash shell, which is the default shell of most Linux distributions including a fresh Ubuntu install, the command is

      export EDITOR=vi
      

      This can be added to your ~/.bash_profile file. If ~/.bash_profile does not exist, you can create one with just the export line.

  3. If you have installed Ubuntu on your own home machine, and you'd like change the system default editor for all users, you can change this with the command:

    sudo update-alternatives --config editor
    

    to select vim.

  4. More generally on just about any UNIX/Linux distribution for which you are the administrator, you can change the system default editor by putting:

    setenv EDITOR vi
    

    in your /etc/csh.login (or /etc/.login, on Solaris) file and putting the lines:

    EDITOR=vi
    export EDITOR
    

    in your /etc/profile file.

Working from Home

This class will use the standard UNIX/Linux/GNU utilities and C development tools as well as subversion as they are found on the department machines running Ubuntu. The supported means for you to work is by using the machines in our computer lab, but it is also possible to work from other locations by either using ssh or by installing Linux on your own computer:

  • ssh into the department machines. Several of the machines in the main lab or left booted into Linux all of them time. You can connect an ssh terminal to these machines from your local machine. These machines are named in numerical sequence starting with main201.cs.utsa.edu. Most Linux machines and Mac OS X have (or can have) openssh installed through their standard package installation process. For Windows, you might try PuTTY.
  • Use your own Linux installation. Linux is free and quite easy to install on your own computer. I generally recommend the Ubuntu distribution for Linux for ease of use. For an "enhanced learning experience," you might also consider the Debian or Gentoo distributions. For Windows users, the least intrusive way to setup Ubuntu is to use: WUBI. Other options include a standard dual-boot install, dedicating a computer to Ubuntu, or setting up virtualization through KVM/QEMU, Xen, VirtualBox, Parallels, or VMWare (the first three of these virtualization systems are free, open source software) so you can run Windows and Linux programs simultaneously. For more information about installing, administering, and using Ubuntu, you may wish to consult the Ubuntu Pocket Guide and Reference.

    If you do a base Ubuntu install, you will want to make sure that the packages build-essential (C compiler tools), subverison and ssh get installed. This can be accomplished with the command:

    sudo apt-get install build-essential subversion ssh
    

    Some additional tools for checking/debugging your C programs include valgrind, splint, and ddd:

    sudo apt-get install valgrind splint ddd
    
Jeffery von Ronne
Department of Computer Science
The University of Texas at San Antonio