wgrib2 – New Version 3.7 – How to Compile & Install on MacOS – Advanced Users Guide

Version 3.7 just released on 4/24/25.
Updated 04-28-25,

Updated 07-28-25 to include brew install libpng
Updated 07-29-25 : added instructions to use Multi-core processing with OpenMP

I’ve recently posted a guide to installing wgrib2 v. 3.7 for beginners. Many of you interested in wgrib2 functionality are already experienced Mac users with knowledge of Terminal commands and the command line interface.

Here’s the advanced users guide to installing wgrib2 v.3.7 on Mac Sequoia – Apple Silicon. If you get hung up, you can always look at the beginners guide.


(If you’re upgrading from older wgrib2 3.1.x, be sure to remove the grib2 folder in the /opt/homebrew and place it on your desktop. Also delete the symlink in your /opt/homebrew/bin folder. You can always copy it back if you have problems with this upgrade; but you’ll need to create a new symlink in the bin folder if you decide to revert back.)

Install Apple Command Line tools : xcode-select --install

Install Homebrew package Manager https://brew.sh/

Using Homebrew, install the following-

brew install gcc

brew install cmake

brew install zlib libpng

brew install openblas

brew install lapack

brew install jasper

brew install libaec

brew install pkg-config

Download the three packages needed: NCEPLIBS-ip, NCEPLIBS-g2c, NCEPLIBS-wgrib2 from Github. Run one command below at a time.

cd ~/Downloads
git clone https://github.com/NOAA-EMC/NCEPLIBS-ip.git


git clone https://github.com/NOAA-EMC/NCEPLIBS-g2c.git


git clone https://github.com/NOAA-EMC/NCEPLIBS-wgrib2.git



Edit any options in the CmakeLists.txt file of two of the packages so that these particular options are as shown below (g2c and wgrib2). The other options can be left as the default values.

NCEPLIBS-ip— No CmakeLists.txt edits needed



NCEPLIBS-g2c—

option(USE_PNG “Use PNG library” ON)
option(USE_Jasper “Use Jasper library” ON)
option(USE_OpenJPEG “Use OpenJPEG library” OFF)
option(USE_AEC “Use LibAEC library” ON)
option(BUILD_SHARED_LIBS “Build shared libraries” ON)
option(BUILD_STATIC_LIBS “Build static libraries” ON)
option(BUILD_G2C “Build the g2c file-based API.” ON)


NCEPLIBS-wgrib2—

option(USE_IPOLATES “Use Ipolates” off)    Change to ON
option (USE_G2CLIB_HIGH “Use g2c high-level decoder (-g2clib 2)?”   Change to ON
option (USE_G2CLIB_LOW “Use g2c high-level decoder (-g2clib 2)?”   Change to ON
option(USE_AEC “Use AEC to enable…) ON
If you’ll want the Multi-core processor option, (why not?) change this
option(USE_OPENMP “Use OpenMP?” Change to ON)

Copy the three package folders that should be in your Downloads folder. Paste them in the the directory /opt/. Use the Finder command Command-Shift-G to enter the /opt/ directory.

Run and install each of the three packages build and compile commands. There are several commands in each block below. Run each command one at a time. Do NOT copy and paste the entire block at once.

cd /opt/NCEPLIBS-ip


sudo mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/homebrew/opt/NCEPLIBS-ip


sudo cmake .. -DCMAKE_INSTALL_PREFIX=/opt/homebrew/opt/NCEPLIBS-ip
-DBUILD_SHARED_LIBS=ON \
-DBLAS_LIBRARIES=/opt/homebrew/opt/openblas/lib/libblas.dylib \
-DLAPACK_LIBRARIES=/opt/homebrew/opt/lapack/lib/liblapack.dylib



sudo make -j$(sysctl -n hw.logicalcpu)


sudo make install

cd /opt/NCEPLIBS-g2c

sudo mkdir build && cd build


export JASPER_INCLUDE_DIR=/opt/homebrew/opt/include/jasper
export JASPER_LIBRARIES=/opt/homebrew/opt/lib/libjasper.dylib
export JPEG_INCLUDE_DIR=/opt/homebrew/opt/include
export JPEG_LIBRARY=/opt/homebrew/opt/lib/libjpeg.dylib


sudo cmake .. -DCMAKE_INSTALL_PREFIX=/opt/homebrew/opt/NCEPLIBS-g2c \
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 \
-DCMAKE_OSX_ARCHITECTURES=arm64


sudo make -j$(sysctl -n hw.logicalcpu)


sudo make install

Next we will install wgrib2. You have a choice. If you would like to have multiprocessor/multi-core support when running wgrib2, use the second choice below (in green). You need to have selected that to “ON” earlier.

# for non-multicore support use this block
# of commands

# for multicore support, use the green block below

cd /opt/NCEPLIBS-wgrib2


sud mkdir build && cd build


sudo cmake .. \
-DCMAKE_INSTALL_PREFIX=/opt/homebrew/opt/NCEPLIBS-wgrib2 \
-DCMAKE_PREFIX_PATH="/opt/homebrew/opt/NCEPLIBS-ip;/opt/homebrew/opt/NCEPLIBS-g2c" \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++



sudo make -j$(sysctl -n hw.logicalcpu)



sudo make install
# for multicore support use the commands in this #block.  You must have selected (USE_OPENMP "Use #OpenMP?" Change to ON 
# You must check
# which version of gcc is installed in your machine.
# This is for gcc-14. Look in your /bin directory

# Change the gcc version number to match your gcc version (like gcc-15).



cd /opt/NCEPLIBS-wgrib2

mkdir build && cd build


if [ ! -f /opt/homebrew/lib/gcc/14/libgomp.dylib ]; then
sudo ln -sf /opt/homebrew/lib/gcc/14/libgomp.1.dylib /opt/homebrew/lib/gcc/14/libgomp.dylib
fi


export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"


sudo cmake .. \
-DCMAKE_INSTALL_PREFIX=/opt/homebrew/opt/NCEPLIBS-wgrib2 \
-DCMAKE_PREFIX_PATH="/opt/homebrew/opt/NCEPLIBS-ip;/opt/homebrew/opt/NCEPLIBS-g2c" \
-DCMAKE_C_COMPILER=/opt/homebrew/bin/gcc-14 \
-DCMAKE_CXX_COMPILER=/opt/homebrew/bin/g++-14 \
-DCMAKE_Fortran_COMPILER=/opt/homebrew/bin/gfortran-14 \
-DUSE_OPENMP=ON \
-DOpenMP_C_FLAGS="-fopenmp" \
-DOpenMP_C_LIB_NAMES="gomp" \
-DOpenMP_C_LIBRARIES="/opt/homebrew/lib/gcc/14/libgomp.dylib" \
-DOpenMP_gomp_LIBRARY="/opt/homebrew/lib/gcc/14/libgomp.dylib" \
-DCMAKE_EXE_LINKER_FLAGS="-L/opt/homebrew/lib/gcc/14 -lgomp"


sudo make -j$(sysctl -n hw.logicalcpu)


sudo make install



8. Create symlink for wgrib2

ln -s /opt/homebrew/opt/NCEPLIBS-wgrib2/bin/wgrib2 /opt/homebrew/bin

9. Create $PATH edits in your .bash_profile (I’m using bash shell here)

echo 'export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-wgrib2/lib:$DYLD_LIBRARY_PATH"' >> ~/.bash_profile
echo 'export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-ip/build/install/include_4:$DYLD_LIBRARY_PATH"' >> ~/.bash_profile
echo 'export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-g2c/lib:$DYLD_LIBRARY_PATH"' >> ~/.bash_profile 
echo 'export DYLD_LIBRARY_PATH="/opt/homebrew/opt/NCEPLIBS-ip/lib:$DYLD_LIBRARY_PATH"' >> ~/.bash_profile 
source ~/.bash_profile

Quit and restart Terminal to reload the changes.

To invoke wgrib2, simply run these two commands—

which wgrib2
wgrib2

You should see the directory of wgrib2 displayed as well as a summary of wgrib2 command functions.


Weather… and Other Things 'Up in the Air'