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

Version 3.7 just released on 4/24/25. This tutorial has been updated 04-28-25.

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 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

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
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-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

cd /opt/NCEPLIBS-wgrib2

sudo 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

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)

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

Weather… and Other Things 'Up in the Air'