Linux environment for COMS W3136 & W3157

CLIC lab

All hw assignments in this class will be graded on one of the CLIC machines. All CLIC machines have identical configurations:

Ubuntu Linux 12.04 64-bit.

This means that either you do all your programming on CLIC or you make sure your submission will run on CLIC before you submit.

If you are NOT familiar with Linux environment, you need to become familiar with it ASAP. I recommend you spend some time this week in the CLIC lab to learn basic Linux. This link came up top when I googled for “linux tutorial for beginners”:

The first 5 chapters (up to “Tutorial Four”) cover the basics to get you started. (Don’t bother with the rest of the chapters.) You may also want to go to a bookstore and pick up a good book on using Linux. There are many.

Even if you are planning to use the CLIC machines remotely, I recommend you visit the lab at least once and make sure you can login and work there. This might come in handy, in case your home internet connection is down, for example.

Accessing CLIC remotely

If you don’t want to work in the CLIC lab, you can access the CLIC machines remotely from your own computers.

On a Mac or Linux, launch the “Terminal” app, and type:

ssh -X

On Windows, you can use MobaXterm.

Running your own UNIX

Being able to log in and work on a CLIC machine is all you need for this course. This section talks about how you can setup your own Linux machine to work locally on your own computer instead of connecting to a CLIC machine. If this does not interest you, you can skip this section. Or maybe skip this section for now, and come back to it later if and when you find working remotely on a CLIC machine less than satisfactory.

First off, before you submit your homework, you should move your code to your CLIC account, test it, and submit it from there. Even if you run the same Ubuntu 12.04 64-bit, things may break in a different configuration (CLIC can have a different version of gcc, for example.) So always test on CLIC before you submit.

For Mac and Windows machines, there are three ways to setup a UNIX environment:

  1. Programming on Mac

    Mac is UNIX, so it is very similar to Linux. If you install Xcode, you get gcc. However, there are enough difference in them so that fixing up your code to run on CLIC won’t be completely trivial. If you go this route, make sure you leave at least a few hours before the deadline to do the testing on CLIC in case something weird comes up and you don’t know how to fix it. In my opinion, this is not worth it, especially when you have the option (3) below.

  2. Programming on Windows

    Windows is very different from Linux. Its native programming environment (Microsoft Visual Studio) looks and acts nothing like Linux.

    There are ways to make Windows look and feel similar to Linux. These involves installing 3rd party extensions such as Cygwin or MinGW. But they are not the same. (It’s been a few years since I tried them, but I don’t think they changed much.) There are just too many differences to make this a viable option. Not recommended.

  3. Running Linux as a virtual machine in Mac or Windows

    You can run Linux in a virtual machine using VirtualBox. You can use VMware too, but it’s not free, so I don’t see the point when VirtualBox free and just as good. (CRF gives you VMware for free, but it will expire in one year.)

Picking your editor

The official way to code in this course is to use a text editor and command line tools. There are two popular text editors in the UNIX environment: Emacs and Vim. They split power users and programmers in UNIX world into two camps (that constantly make fun of each other). The choice between them largely boils down to personal taste. I recommend you pick one of those as your editor and start using it, learning tips and tricks as you go. You can start with the built-in tutorials: run vimtutor at the command prompt for Vim, and click on “Emacs Tutorial” under Help menu for Emacs. Emacs and Vim have been ported to virtually every platform, so you can install and use them on your PC or Mac as well.

Another possibility is Nano (also called Pico). Nano is very easy to use, especially for beginners, but it is rather limited in functionality. It is only recommended for those who are new to UNIX and feel there are just too many things to learn before you get to do anything. Even so, I recommend that you switch to either Emacs or Vim as early as possible.

Setting up your shell environment

The application that you interact with in a terminal window – the thing that prints the command prompt and carries out the commands that you type – is called a “shell”. First, you need to make sure you are running a correct shell. Try typing echo $SHELL. You’re good if you see /bin/bash. If not (and you’re not a UNIX wiz who actually want something different), contact CRF and tell them to change your login shell to “bash”. Until they do, you have to manually type /bin/bash as soon as you login in order to switch to a bash shell session.

There is something you need to add to the .bashrc file in your home directory to setup your shell environment for this class. Add the following line at the end of your .bashrc file in your home directory:

export EDITOR=your_editor

(You should of course replace your_editor with either vim, emacs, or nano, depending on what editor you actually use.)

Log out of the computer and log in again. Type echo $EDITOR to see if your modification to .bashrc has taken effect. If it hasn’t, try adding the following lines to .bash_profile file in your home directory:

if [ -f ~/.bashrc ]; then 
    source ~/.bashrc 

Basic UNIX commands

Here are some UNIX commands that you should get comfortable with. You can use the man command to display the manual page for any given command.

man, cat, less, rm, cp, ls, ll (an alias for ls -alF), pwd, cd, mkdir,
alias, locate, gcc, make, touch

Here are some more that you will find handy:

clear, history, date, mv, grep, diff, find, tar

Last updated: 2014–01–20