Home » How to install gnuplot from source on Ubuntu PC?

How to install gnuplot from source on Ubuntu PC?

Remark: This tutorial describes how to install gnuplot 4.6.5 from source on a Ubuntu 14.04 LTS PC, but it can be easily adapted for other versions of gnuplot and/or Linux distributions.

Step 1: Create a new script

All required steps to install gnuplot 4.6.5 will be written in a script called GnuplotSetup.sh (assuming you do not have a file with that name in the current folder already).

To create the file write on the command line the following (excluding the “$” symbol):
$ touch GnuplotSetup.sh

Step 2: Install dependencies and gnuplot

Open the script using your favourite text editor. Assuming this is vi(m) write on the command line the following (excluding the “$” symbol):
$ vim GnuplotSetup.sh

Next write the contents of the script (i.e. copy and paste the text below into the script):

/scripts/blob/master/scripts/linux/GnuplotSetup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
 
###########################################################
#
#
# Gnuplot setup
#
#
###########################################################
 
# Starting setup of Gnuplot
echo "Setting up Gnuplot..."
 
 
#----------------------------------------------------------
# Installing dependent packages
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Installing the dependent packages build-essentials g++ gcc..."
 
# Execute the action
sudo apt-get -y install build-essentials g++ gcc
 
 
#----------------------------------------------------------
# Installing Gnuplot
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Downloading and installing Gnuplot..."
 
# Constant values definitions
FOLDER_NAME="Gnuplot"
 
# Create a new folder for storing the source code
mkdir ${FOLDER_NAME}
 
# Change directory
cd ${FOLDER_NAME}
 
# Download source code
wget http://sourceforge.net/projects/gnuplot/files/gnuplot/4.6.5/gnuplot-4.6.5.tar.gz
 
# Extract archive
tar -xvzf gnuplot-4.6.5.tar.gz
 
# Change directory
cd gnuplot-4.6.5
 
# Configure gnuplot for compilation
./configure
 
# Compile the project
make
 
# Install gnuplot in the default location
sudo make install
 
# Return to the parent directory
cd ../../
 
# Inform user that Gnuplot was successfully installed
echo "Gnuplot was successfully installed."

The comments in the script should provide enough details to understand what each instruction does.

Step 3: Execute script

Add execution permission to the script GnuplotSetup.sh using the following (excluding the “$” symbol):
$ chmod +x GnuplotSetup.sh

Finally execute the script as below (excluding the “$” symbol):
$ ./GnuplotSetup.sh

9 comments

  1. Ashim says:

    Thanks a ton! I am at loss of words to express my gratitude. I was struggling with this for sometime. Finally got you! 🙂

    • In order to get an interactive terminal for gnuplot 4.6.5 run gnuplot from a terminal window; to exit press CTRL + D.

      If you want to remove gnuplot from your PC then:

      1. Do not remove the installation folder (rm -rf ${FOLDER_NAME});
      2. Run sudo make uninstall from the same folder from which you run sudo make install.
      • Juraj says:

        You put the (rm -rf ${FOLDER_NAME}) command into the script, I have done it that way. something has been installed wrong and now it runs but cant plot etc. the new and the old version are mixed i think or something similar.
        the problem is, i cannot unistall becuse i removed the files.
        Can you help?

        • By rerunning the script in exactly the same way as before up to the ./configure line (i.e. line 52) the generated Makefiles should correspond to the same paths. Therefore after executing the ./configure line it should be possible to run sudo make uninstall from the same folder to remove all the previously installed files.

          Please let me know if this did not work for you.

  2. Marcelo says:

    Hello,

    I followed the steps above and I got the gnuplot but I cant generate a graphic. I use to write plot ‘xxx.dat’ and doesnt work.
    My ubuntu is 12.04

    Please help me

    • Hello,

      Due to the lack of details it would be very hard for me to help.

      However one easy way to test if gnuplot was set up correctly is to try to run one of the simple sample scripts made available on the official gnuplot website.

      In order to run the scripts from the command line make sure you uncomment the lines in which you set the terminal (e.g. set terminal pngcairo) and the output (set output “test.png”).

      For your convenience please find the contents of a minimum working example (MWE) script below:
      set terminal pngcairo
      set output 'test.png'
      plot [-5:5] sin(x)

      Save the contents of the script in a file (e.g. test.gnu) and then (assuming gnuplot is in your PATH environment variable) run it using the command:
      gnuplot test.gnu

      If the gnuplot execution is successful a “test.png” file should be generated in the current directory.

  3. Anju says:

    Hi,
    I could install gnuplot in the same way that you explained. But I am not getting any plots. What should I do?

Leave a Reply

Your email address will not be published. Required fields are marked *