(Last update: 24-Jan-2013)

What follows is a description of the procedure I have followed to have PGPLOT working under Mac OS X and Linux. Note that this is a two step procedure: you need to install the graphic library first, and then define some environment variables that are needed in order to work comfortably with PGPLOT. In this sense it is useful to check that the demo programs run properly.

Mac users

One of the easiest way to install PGPLOT is to make use of MacPorts. Check if MacPorts is already working in your system, and if PGPLOT is already installed, trying to execute:
$ port installed pgplot
If the previous command does not work, you need to install MacPorts first.

I installed MacPorts downloading the "dmg" disk image installation file corresponding to my OS Version (Snow Leopard) from here. After the installation, one needs to execute (in order to ensure you have the latest revisions to the "Portfiles" needed when building and installing ports):
$ sudo port -v selfupdate

Once MacPorts is available, you can trivially install many packages, in particular PGPLOT:
$ sudo port install pgplot
Note that the previous command can take several minutes if the system detects the need of installing additional packages.

The different versions of the PGPLOT library (libpgplot.* and libcpgplot.*) are installed under: /opt/local/lib. The X11 server is installed in /opt/local/bin/pgxwin_server, whereas auxiliary files (including the demos) are placed under:/opt/local/share/pgplot.

After the installation, make sure that the expected environment variables are properly set (at least PGPLOT_DIR must exist; PGPLOT_DEV is also quite useful). You can check this by executing:
$ echo $PGPLOT_DIR
$ echo $PGPLOT_DEV

If the previous environment variables are not set, you can easily define them:
$ export PGPLOT_DIR=/opt/local/lib
$ export PGPLOT_DEV=/Xserve
It is useful to introduce those definitions in the .bashrc file at the home directory of the user.

Execute any of the demos in order to check that everything is fine:
$ /opt/local/share/pgplot/examples/pgdemo1
$ /opt/local/share/pgplot/examples/pgdemo2
$ /opt/local/share/pgplot/examples/pgdemo3
...

Finally, compile your own code. For example, is gfortran was the fortran compiler employed to install PGPLOT, the following command should work:
$ gfortran -o outputFileName inputFotranFile.f -L/opt/local/lib -lpgplot -lX11
Note that you should use the same fortran compiler to install PGPLOT and to compile your own files. In the above example the X11 library was assumed to be installed in /opt/local/lib. If this is not the case, include an extra -L/directory_path_to_libX11 in the compilation command before -lpgplot.

(Mac users may find also useful the instructions provided by Benjamin Weiner)

Linux users

In Linux I always download the original source code of PGPLOT from its homepage, and install the package manually (at the time of writting these notes, the latest version is pgplot5.2.tar.gz). For this to work properly, the appropriate X11 files must be available in your machine. I also install gfortran as the Fortran compiler. Both tasks can be performed executing:

In order to install PGPLOT, I follow (with a minor but important modification: the use of gfortran instead of g77) the instructions given by T.J. Pearson to install this library under Linux, which can be summarized as follows:
  1. Download the distribution file pgplot5.2.tar.gz
  2. Decompress and extract the contents of the distribution file in a source directory. In this sense, I always place pgplot5.2.tar.gz under /usr/local/src. Note that for this opperation it is probably required that you have root privileges, unless you have write access to the directories. I indicate that by changing the prompt symbol from $ to #. You can either log in as root (using su in Fedora and CentOS, or using sudo su in Ubuntu), or use sudo in front of the following commands:
    # cd /usr/local/src
    # mv ~/Downloads/pgplot5.2.tar.gz .
    # tar zxvf pgplot5.2.tar.gz
    The last command will create /usr/local/src/pgplot and subdirectories.
  3. Create the directory where PGPLOT will be actually installed:
    # mkdir /usr/local/pgplot
    # cd /usr/local/pgplot
  4. Copy the file drivers.list from the source directory to the installation directory:
    # cp /usr/local/src/pgplot/drivers.list .
  5. Edit that file and remove the exclamation mark (first column of each row) in front of the following graphic devices: /PS, /VPS, /CPS, /VCPS and /XServe. The resulting file is also available here: drivers.list.
  6. Create the makefile. From the installation directory /usr/local/pgplot execute:
    # /usr/local/src/pgplot/makemake /usr/local/src/pgplot linux g77_gcc_aout
  7. Edit the file makefile and change the line:
    FCOMPL=g77
    by
    FCOMPL=gfortran
  8. Compile the source files:
    # make
    # make cpg
    # make clean

After the installation, make sure that the expected environment variables are properly set (at least PGPLOT_DIR must exist; PGPLOT_DEV is also quite useful):
$ export PGPLOT_DIR=/usr/local/pgplot
$ export PGPLOT_DEV=/Xserve
It is useful to introduce those definitions in the .bashrc file at the home directory of the user.

Execute any of the demos in order to check that everything is fine:
$ /usr/local/pgplot/pgdemo1
$ /usr/local/pgplot/pgdemo2
$ /usr/local/pgplot/pgdemo3
...

Finally, compile your own code. For example, is gfortran was the fortran compiler employed to install PGPLOT, the following command should work:
$ gfortran -o outputFileName inputFotranFile.f -L/usr/local/pgplot -L/usr/X11/lib -lpgplot -lX11
Note that you should use the same fortran compiler to install PGPLOT and to compile your own files. In the above example the X11 library was assumed to be installed in /usr/X11/lib. If this is not the case, include the actual directory using -L/directory_path_to_libX11 in the compilation instead of -L/usr/X11/lib above.