How to compile GRASS GIS on MS Windows

This page explains how to compile portable GRASS GIS on MS Windows using these scripts.

There is a great wiki page that explains a step-by-step procedure on how to compile GRASS GIS on MS Windows, but it requires the installation of Visual Studio (optionally?) and installs compiled GRASS GIS into the OSGeo4W directory structure. Since I just wanted to compile and run it from the Git repository, I needed to slightly modify the steps in the wiki page.

See also How to cross-compile GRASS GIS for MS Windows.

1   Installing OSGeo4W

  1. Download and run the OSGeo4W installer (osgeo4w-setup.exe)
  2. Advanced Install, Next
  3. Install from Internet, Next
  4. C:\OSGeo4W, Next
  5. Next
  6. Direct Connection, Next
  7. Select a download site, Next
  8. Install the following packages:
    • python3-pip
    • python3-wxpython
    • python3-pywin32
    • proj-devel
    • gdal-devel
    • pdal-devel
    • liblas-devel
    • netcdf-devel
    • geos-devel
    • libtiff-devel
    • libpng-devel
    • sqlite3-devel
    • cairo-devel
    • freetype-devel
    • zstd-devel

Or

  1. Download the OSGeo4W installer (osgeo4w-setup.exe)
  2. Start the cmd window
  3. Run the following command in the cmd window:
    osgeo4w-setup.exe -A -g -k -q -s https://download.osgeo.org/osgeo4w/v2/x86_64/ -P python3-pip,python3-wxpython,python3-pywin32,proj-devel,gdal-devel,pdal-devel,liblas-devel,netcdf-devel,geos-devel,libtiff-devel,libpng-devel,sqlite3-devel,cairo-devel,freetype-devel,zstd-devel

Install some Python modules from the OSGeo4W Shell.

# matplotlib for r.area.createweight
# scikit-learn for r.learn.ml2
# python-dateutil for t.rat.boxplot
pip install scikit-learn python-dateutil matplotlib

2   Installing MSYS2

  1. Download and run the MSYS2 installer (as of October 28, 2022, 64-bit installer)
  2. Next
  3. C:\msys64, Next
  4. Next
  5. Uncheck Run MSYS2 64bit now, Finish
  6. Run MSYS2 MinGW 64-bit
  7. Install the following packages
    pacman --noconfirm -S tar libintl make flex bison diffutils git dos2unix zip
  8. Install these packages:
    • mingw-w64-x86_64-gcc for a full GCC environment
    • mingw-w64-x86_64-bzip2 for configure -lbz2
    • mingw-w64-x86_64-libsystre for configure -lregex
    • mingw-w64-x86_64-fftw for configure -lfftw
    • mingw-w64-x86_64-lapack for configure -lblas -llapack
    • mingw-w64-x86_64-pkg-config for configure -lcairo -lfreetype
    • mingw-w64-x86_64-dlfcn for v.feature.algebra
    pacman --noconfirm -S mingw-w64-x86_64-gcc libbz2-devel mingw-w64-x86_64-libsystre mingw-w64-x86_64-fftw mingw-w64-x86_64-lapack mingw-w64-x86_64-pkg-config mingw-w64-x86_64-dlfcn

3   Compiling GRASS GIS

# add two export lines to ~/.bash_profile
cat <<'EOT' >> ~/.bash_profile
export LC_ALL=C

# for OSGeo4W
export PATH="/c/osgeo4w/bin:/mingw64/bin:$PATH"
export PROJ_LIB="/c/osgeo4w/share/proj"
export PYTHONHOME="/c/osgeo4w/apps/python39"
EOT

# source ~/.bash_profile
. ~/.bash_profile

mkdir -p ~/usr/local/src
cd ~/usr/local/src

# download the GRASS build scripts in ~/usr/local/src/grass-mingw-scripts
git clone https://github.com/HuidaeCho/grass-mingw-scripts.git

# download the GRASS source code in ~/usr/local/src/grass
git clone https://github.com/OSGeo/grass.git

cd grass

# build GRASS
../grass-mingw-scripts/myconfigure.sh
../grass-mingw-scripts/mymake.sh

# create grass.bat in bin.x86_64-w64-mingw32
../grass-mingw-scripts/mkbats.sh

Now, grass.bat is ready to run directly from the source directory C:\msys64\home\USER\usr\local\src\grass\bin.x86_64-w64-mingw32\grass.bat. Just run this batch file to start GRASS GIS on your machine.

4   Installing GRASS GIS on MS Windows

# package the build
../grass-mingw-scripts/package.sh

Now, move to another Windows machine and extract the following ZIP file anywhere: C:\msys64\home\USER\usr\local\src\grass\grass80-x86_64-w64-mingw32-osgeo4w64-YYYYMMDD.zip

5   Starting GRASS GIS

You can start GRASS GIS by running OSGeo4W\opt\grass\grass.bat.

6   Changing the default shell

To change the default shell from cmd.exe to something else, define a new environment variable called GRASS_SH:

  1. Control Panel
  2. User Accounts
  3. Change my environment variables
  4. Add a new user variable GRASS_SH=powershell (your choice of a shell)
  5. Start grass.bat

If you want a bash-like shell, download busybox64.exe as C:\bin\sh.exe and set GRASS_SH=C:\bin\sh.exe.

7   Latest daily build

7.1   How to install it

  1. Extract this zip file anywhere including an external drive for portability
  2. Run OSGeo4W\opt\grass\grass.bat

7.2   Official daily builds

Please note that this build is not an official daily build from the GRASS GIS development team. It is my personal daily build packaged as a ZIP file using compile.sh. This script compiles the latest main branch of the official GRASS GIS repository and packages everything GRASS GIS requires including OSGeo4W and Python 3.

References