[UNDER CONSTRUCTION, Comments are welcome.]
I wanted to outline some steps necessary to get started with Linux and computing for economics.
Warning
It is possible to destroy your system if you don't know what you're doing. Be sure to backup files before you do any installation. Dual-boots are a headache, so if possible use a computer you can install only Linux on (not Linux and Windows).
What you need
A PC (i.e., do not install Linux on a Mac)
A flash drive or a writable DVD disc
Installing Linux
Download your preferred "distribution". I will give the steps for Ubuntu.
Download Ubuntu. To install via a flash drive, follow this. Otherwise, follow this.
Getting software
Much of Linux is done in the "Terminal." This is an application similar to command prompt on windows. You can put this on the startup bar for easy access.
To install the free gfortran compiler, open the terminal and type "sudo apt-get install gfortran".
Close the terminal. Now, to ensure that it installed, open up the terminal again, and type "which gfortran". If it did not find gfortran, there was an error in installation. If it did find gfortran, type "gfortran --version". It should display some info, and hopefully you have version 5.0 or higher.
To get BLAS and LAPACK you proceed similarly. Type "sudo apt-get install libblas-dev" for BLAS and "sudo apt-get install liblapack-dev" for LAPACK.
Basic Linux commands
To get around in Linux, you need to know some basic commands that can be entered in the terminal. Notation <something> means fill in the blank with "something".
ls --- list the files in your current directory/folder
ls -al --- list all files, including hidden files, in your current folder. Hidden files have a period in front of them.
ls <folder/directory> --- lists the contents of the specified folder
pwd --- display the path of the current folder
cd <desired folder/directory> --- changes from your current folder to the desired one
cd --- without any arguments changes to your home directory.
cd ~ --- changes to your home directory
cd .. --- the two periods say go up a folder (i.e., go to the parent directory)
cd . --- doesn't do anything, one period means "this directory", so "cd ." changes to the current directory, but you are already there.
mv <file1> <location or file2> --- moves file1 to either a location or renames it as file2 (or both.
Example #1: "mv a.txt b.txt" renames a.txt as b.txt.
Example #2: "mv a.txt ./mydir/" moves a.txt into a subfolder called mydir.
cp <file1> <location> --- copies file1 to a the specified location
Example #1: "cp a.txt ./mydir/" will create a copy of a.txt inside the subfolder mydir
tar -xvzf <somefile-ending-with-.tar.gz> --- .tar.gz files are like .zip files for Linux, this will extract it to the present directory.
cat <file> --- displays the contents of "file" to screen.
man <program name> --- display the man (i.e. manual) page of a program.
<program> --help --- display some basic help info (such as calling syntax).
Configuring your system
Your home directory is denoted by a tilde "~". That is a short-hand for the actual directory which is a path like /home/<yourusername>/
There is a very important file called ~/.bashrc (the file name has a period in front of it, which means it is hidden). This is a "script" that runs every time you open the terminal. You will often need to come to this file and edit it when you install software. I would add the following commands to it:
export FC=gfortran --- this sets the default fortran compiler
export CC=gcc --- this sets the default C compiler
export CXX=g++ --- this sets the default C++ compiler (ensure g++ is installed, "sudo apt-get install g++")
export OMP_STACKSIZE=2M --- this sets the default stacksize for OpenMP (don't worry if you don't know what I am talking about)
export OMP_NUM_THREADS=<number of cores on your system> --- this sets the default number of threads for OpenMP
ulimit -s unlimited --- this sets the default stacksize to be unlimited (preventing most stack overflows when NOT using OpenMP)
alias open="gvfs-open " --- now, whenever you type "open <some file>", the default program will open it. E.g., "open readme.txt" will open up your default editor.
Editing and compiling some applications
As your first text editor, Ubuntu comes with "gedit". This is somewhat nice as it has syntax highlighting for Fortran. However, it also has some quirks such as how it handles tabs. Ensure that it it is using spaces for tabs by following these instructions. I would also change the default number of spaces to 4 (personal preference). Later on, you may want to switch to vim (can be installed via "sudo apt-get install vim") or Emacs. I use vim.
Create your first Fortran program
Make a "main.f90" file and save it somewhere
Open the command prompt and navigate to where you saved it via "cd <folder where you saved it>"
Compile it with gfortran: gfortran main.f90.
Ensure that it produced the executable by typing "ls" --- there should be a file called a.out
Run the executable by typing "./a.out". Don't forget the first "./".
Your next challenge is including files and linking them. Here is how you could link with BLAS.
Create a test multiplication program that calls "dgemm".
Ensure the libblas is installed where I think it probably is. In particular, type "ls /usr/lib" and look around for libblas.a or libblas.so. If so, continue.
When you compile it, use gfortran main.f90 -L/usr/lib/ -lblas. Actually, since the library is /usr/lib which is a special folder, you can probably get away with just gfortran main.f90 -lblas.
Hopefully, it compiled without error and you can try to run a.out again by typing "./a.out"
For the future
Learn about linux tools such as "grep" and "sed" for processing and searching text files, as well as what's called piping via " | ".
Learn about "redirecting output" via > and 2>
Learn about "ssh" and "nohup" for running applications on servers.
Figure out how to install software from source. Often times, this is as simple as typing "make clean" and "make" and "make install". Other times, you will need a configure step such as "./configure <options>".
Figure out how to create your own makefiles.
Figure out how to use a better text editor like Vim or Emacs.
Learn how to write bash scripts.