How to install and wgrib2 in linux

Dear All,

Now we are going to see how to install wgrib2 and g2ctl in our linux machine, for the Grib version 2 data.

step 1:

First of we need to install GRADS

From the above link we can get the source.

In ubuntu we need to install some dependencies,

$ sudo apt-get install libgrib2c-dev libgrib2c0d (to install wgrib2 correctly)

$ sudo apt-get install grads  (for gribmap)

Note : grads version must be equal or higher than the 2.0.a8 (to work correctly for grib2).

If you are using ubuntu 10.04, then grads may be lower than the above version.

So download the source of grads version 2.0.a8 or higher.

$ sudo apt-get install libxmu-dev libxmu-headers x11-common x11-xserver-utils

Extract that downloaded grads source and change directory into that extracted folder.

$ ./configure

$ make && make install

Now it should be installed in that folder called ‘src’.

You can use this grads, gribmap (inside the src folder of the extracted folder of grads2.0.a8) to use the grib2 version.

$ sudo cp -r src /usr/local/grads2.0.a8

Edit your home .bashrc file, add the following lines.

alias grads=’/usr/local/grads2.0.a8/grads’

alias gribmap=/usr/local/grads2.0.a8/gribmap’


step 2:

From the below site we can download the perl source code

Look in the bottom of the page.

Try to open all the above links in firefox not in chrome.

Download that source code from here  save as . If that perl source code has viewed by web page itself means, copy that perl code into one text file, and save that as file in your home folder itself.

step 3:

Go to the below link to download the wgrib2 tar file

From here you can download the wgrib2.tgz source file in the above link.

Go to this section in the above link “Source Code and Compling Hints” .

Download the “wgrib2.tgz” by http way.

After downloaded the wgrib2.tgz file, extract it either by GUI “Extract here” or

$ tar -zxvf wgrib.gz

It should create directory called “grib2″.

Now move this folder into /usr/bin by

$ sudo mv grib2 /usr/bin/

Now go to that directory by

$ cd /usr/bin/grib2

$ sudo make

It takes few minutes to install wgrib2 inside that folder itself.

Note : now our wgrib2 executable path is ” /usr/bin/grib2/wgrib2/wgrib2 “.

step 4:

Now open the file,

  1. Look for the line:
    and change it to point to your wgrib2 path. In our case,
  2. Don’t forget to make the program  as executable (chmod 755 and put it on your PATH. i.e $ sudo chmod 755    and  $ sudo cp  /usr/bin/

Thats it … !

Now you can access the from the bash shell (terminal) itself.

Try the following usage of g2ctl with your analysis and forecasting binary grib files.


For analyses:

$ -0 grib2_file >grib2_file.ctl    [ here we passed zero option]
$ gribmap -0 -i grib2_file.ctl        [ here we passed zero option]
$ grads
Landscape mode? (no for portrait):
ga-> open grib2_file.ctl 

For forecasts:

$  grib2_file >grib2_file.ctl
$ gribmap -i grib2_file.ctl
$ grads
Landscape mode? (no for portrait):
ga-> open grib2_file.ctl

The main differences between the syntax of and are,

  • For grib version 2 files, we are using script to create ctl files. The usage option -0 (zero) are passed for both and gribmap commands for analysis files and not for forecast files in the grib version 2.
  • For grib version 1 files, we are using script to create ctl files. The usage option -0 (zero) is passed in gribmap command for analysis files and option -verf is passed in command for forecast files. To know more about script, how to install that and how to use that, click here .

To understand, what is grib and ctl file formate

grib is the one of binary file formate to store the analysis and forecast data in some kind of structured manner.
ctl means control file in ascii formate. we can read it. Both these formates are usually used in atmospheric and meteorological departments.

The generated ctl files can be read and visualized by GRADS , CDAT and other meteorological softwares.

Both Grads and CDAT are open source software.

More over many other foss applications are available for the same kind of stuff.



About arulalant

Currently working as "Project Scientist – C" in National Centre for Medium Range Weather Forecasting (NCMRWF), MoES, Noida, India
This entry was posted in CDAT and tagged , , , , . Bookmark the permalink.

41 Responses to How to install and wgrib2 in linux

  1. Ugwoke says:

    Hello Arulalant,
    I have an issue compiling wgrib2, while in grib2, i did the command ‘sudo make’ but i get an error ‘makefile:362: *** ERROR, fortran compiler (enironment vararible FC) is not recognized. Stop.’
    what’s the way forward? Thanks


    • Pogoda33 says:

      Before “make” in grib2 folder you must enter
      export CC=gcc
      export FC=gfortran


      • Ugwoke says:

        Thank so much Pogoda33. I have actually tried this your commands but the error ‘makefile:362:*** ERROR, fortran compiler ( environment variable FC) is not recognised. Stop’ persists .


        • nancywang says:

          I have the same problem. Did you solve this ?


        • dakangwang says:

          Hello Ugwoke,did you solve this problem?I met the same case as you had,and I have tried the commands export CC=gcc export FC=gfortran before “make” ,but still error,I am so puzzled.please help me,Thandks very much!


          • AnthonyM says:

            Hello, I had a similar problem and solved it by opening the Makefile and uncommenting the lines:- export CC=gcc, export FC=gfortran. I hope it works for you also

            Liked by 1 person

            • dakangwang says:

              Thanks AnthonyM,you are very warmhearted,I had solved this problem by the means as you said,thank you all the same and hope anyone else who would encounter this problem can see what you put!


  2. Manuel victor says:

    thank you guy for all you have done

    now i want to know how can I install wgrib2 and g2ctl on mac have you got any idea? or should I just follow the same step like in linux?


  3. Thank you sooo much you saved my life T^T


  4. burhan says:

    Thanks Arulalan for such a good guide. I am using centos 6.5 and have followed your instructions to install and wgrib2. Everything works fine (g2ctl and gribmap run successfully without errors) until I plot my data on GrADS. It gives all undefined values to my data, yet the data is there!


  5. Ed says:

    Thanks, this is great help.

    I got an error instal wgrib2 :

    ed@ed-VirtualBox:/usr/bin/grib2$ sudo make
    makefile:358: *** ERROR, did not recognize fortran compiler, cannot use IPOLATES, set FC=f90 compiler. Stop.
    Any advice ?



    • Ed says:

      I got this error fixed. In the makefile IPOLATES was by default set to 1, so I changed it to 0. So the installtion works but only up to a point, then it gives me this error

      collect2: error: ld returned 1 exit status
      make[1]: *** [wgrib2] Error 1
      make[1]: Leaving directory `/usr/bin/grib2/wgrib2′
      make: *** [wgrib2/wgrib2] Error 2

      Any thoughts?



      • arulalant says:

        Make sure that wgrib2 executable path /usr/bin/grib2/wgrib2/wgrib2 is working. It seems ld is not working correctly within that folder or not installed properly (make inside grib2).


  6. Thank’s a lot, you are the master…


  7. Ismoil says:

    Dear Arrulan T.
    I’m starting the command “make && make install” and i’m getting error below:

    gxX.c:20:19: fatal error: cairo.h: No such file or directory
    compilation terminated.

    How can I install this cairo.h? I’m using ubuntu 12.04



    • arulalant says:

      Better you do, $ sudo apt-get install grads , instead of install it from source.
      It will take care of it. The thing is you need to install cairo package. That also you can install it from sudo apt-get .


  8. Elif YILMAZ says:

    Dear Arrulan T.

    How can I open the grb2. file that had sent from meteorology center in Linux? Is it as above that you explain? And do you know they can opened in windows 7?


    • arulalant says:

      Dear Eyilmaz,

      You can use the above steps to access grib2 files in linux. I documented here on how to install/setup to access grib2 files in Ubuntu distribution. Moreover you can follow the same steps in other linux distros also.

      I never tried / worked in windows. So I do not know how to setup the same in windows.



  9. goitom says:

    Hello Dear Arulalan.T
    I am using you configuration steps is working for grib1 but when I tray to use it in grib2 it doesn’t work but I install grads 2.0.a9.1 and wgrib2 but is display the following errors.
    bash-4.2$ gribmap -i newforecast.ctl
    grib2map: scanning GRIB2 file: gfs_4_20120601_0000_000.grb2
    grib2map: Writing out the index file

    I am looking your help thank very much for your help


    • arulalant says:

      Hai Goitom.,
      Are you using or ? for grib1 version. for grib2 version data.
      What error it throws ?


      • goitom says:

        Hello Dear Arulalan.T
        I am using and wgrib2 for grib2 , additional i am install wrfems this is the shell script
        #! /bin/csh
        cd /home/model/wrfems/runs/ethiopia/emsprd/grib
        set yymmdd = `date +%y%m%d`
        cat *grb2*>gribdata_$yymmdd-2
        mv gribdata_$yymmdd-2 /home/model/ethiowrf/
        cd /home/model/ethiowrf/ -verf gribdata_$yymmdd-2 >grib.ctl
        gribmap -i grib.ctl

        and the error is grib2map: Writing out the index file and the index files are not read by grads

        thanks for your help


        • arulalant says:

          Dear Goitom,
          I dont think this is an error “grib2map: Writing out the index file”. It seems like it info print statement. Is that created idx file correctly or not. Instead of writing csh script to create ctl, idx file for the model data, I suggest that you would have try it by your hand itself.
          Go to the data directory via terminal and give try to create ctl file and the idx file by there itself. So that will give us more way to find out the error. While you opening “ctl” file in Grads, what error it throws ?


          • Goitom says:

            Dear Arulalan.T
            the individual grib2 file are working properly but the cat file “gribdata_$yymmdd-2” is not working.
            Best regards


            • arulalant says:

              So its not problem with It is problem with “cat *grb2*>gribdata_$yymmdd-2″ command. You have to find the solution for this. I think you can not use cat command for the binary *grb2* files. Try to use cp [copy] instead of cat.
              ” cp *grb2*>gribdata_$yymmdd-2″.
              If this also fails means you have to find the solution.


  10. tony says:

    I work with:
    step 3:
    Go to the below link to download the wgrib2 tar file……
    .. but help me with the data, but no file.idx.
    In GrADS:
    clima@lluvia:~/CFSv2$ perl g2ctl >oceansst.ensm.jan.cfsv2.ctl
    clima@lluvia:~/CFSv2$ gribmap -i oceansst.ensm.jan.cfsv2.ctl
    grib2map: scanning GRIB2 file:
    grib2map: Writing out the index file


  11. quangtuan says:

    Dear Arulalan.T
    How to install wgrib2 in Windows XP?


    • arulalant says:

      Dear Quangtuan,

      I never tried to install grib2ctl in windows.

      First of all you need to install perl and perl dependencies packages in windows.

      Then you need to install wgrib package also in your windows.

      Finally … But I dont know how to install all the above successfully in windows.

      Switch to Free Open Source OS / Linux / Ubuntu !


      • Adem says:

        Dear Arulalant,
        Do you have a similar step by step procedure for installation of wgrib2 in Windows 7?
        How can I install wgrib2 in Windows 7?
        Many thanks


  12. jo says:

    hi, you have same step by step procedure for installation in Windows?


  13. leeladam says:

    Thanks for the great tutorial, you saved me a lot of googling!
    A note: I had to create a symbolic link after step 3 to make my system recognize the wgrib2 command:
    sudo ln -s /usr/bin/grib2/wgrib2/wgrib2 /usr/bin


  14. Andres Duque says:

    Thank you very much, saved my life
    Greetings from Colombia


  15. Naresh Krishna vissa says:

    Thank you very much
    for the useful information


  16. miquel says:

    Many thanks, it worked allright!


    • Adem says:

      Dear Arulalant,
      Do you have a similar step by step procedure for installation of wgrib2 in Windows 7?
      How can I install wgrib2 in Windows 7?
      Many thanks


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s