Skip to content

Instantly share code, notes, and snippets.

@wxguy
Last active August 18, 2025 16:44
Show Gist options
  • Save wxguy/945d18af773c2208a33a5e0429a4b813 to your computer and use it in GitHub Desktop.
Save wxguy/945d18af773c2208a33a5e0429a4b813 to your computer and use it in GitHub Desktop.
A small bash script to compile wgrib2 from source on Ubuntu OS...
#!/bin/bash
# License for this script is GNU 2
# A small bash script to download, compile and install latest wgrib2 from source.
# I have written this script so that I can automate the proceedure whenever I change Linux OS
# Make it executable before running the script using'chmod +x ./wgrib2_auto_compile_script.sh'
# Ensure to run the script with sudo (sudo ./wgrib2_auto_compile_script.sh) or under root environment
# Update the repo
apt update
# Install necessary development packages required for compilation
# Tested on Ubuntu 18.04 and 19.04
apt install -y build-essential libaec-dev zlib1g-dev libcurl4-openssl-dev libboost-dev curl wget zip unzip bzip2 gfortran gcc g++ libwebp-dev libzstd-dev cmake
# Make a working directory for cimpilation
mkdir -p ~/Downloads/wgrib2
# Move to working directory
cd ~/Downloads/wgrib2
# Download the latest wgrib2 source code
wget -c ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz
# Extract the source to current directory
tar -xzvf wgrib2.tgz
# Move to main grib directory for compilation
cd grib2
# Export the flags which are important for compalation.
# If you are using different compilers then the flag is to be modified accordingly
export CC=gcc
export FC=gfortran
# Compile and make binary
make
# Check if the wgrib2 binary is made properly. Not necessary but you can see some output for info
wgrib2/wgrib2 -config
# Remove previous install of grib2 directory
rm -rfv /usr/local/grib2/
# Create the removed directory
mkdir -p /usr/local/grib2/
# Copy the wgrib2 binary to bin directory
# so that it can be executed directly from terminal
cp -rfv wgrib2/wgrib2 /usr/local/bin/wgrib2
# Move out of current working directory
cd ~
# Remove the working directoy.
rm -rfv ~/Downloads/wgrib2
# All fininshed. Now type wgrib2 in terminal and enter. You should see the list of all option wgrib2 supports.
@franra9
Copy link

franra9 commented May 10, 2025

It was very useful thanks!

@iloire
Copy link

iloire commented Aug 17, 2025

In Ubuntu 22.04 I also had to install cmake and a couple of libraries:

sudo apt install cmake
sudo apt install libwebp-dev libzstd-dev

@wxguy
Copy link
Author

wxguy commented Aug 18, 2025

Thank you @iloire ,

Updated the script...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment