Logo
Molecular Dynamics Simulation
gromacs-installation

GROMACS Installation in Ubuntu, Linux

Skilltori

Skilltori

1/2/2026 - min read

Molecular dynamics (MD) simulations are heavily demanding on hardware. While installing software on Linux can sometimes feel daunting, compiling GROMACS from source is a vital skill for computational chemists and biophysicists. Why? Because the default apt repository versions miss out on critical hardware acceleration features specific to your processor and graphics card.

In this comprehensive, step-by-step guide, we will walk through how to install GROMACS on a clean Ubuntu system from absolute zero, ensuring your hardware runs simulations at peak performance.

Testing Environment Note: Phase One of this installation guide took approximately 15–20 minutes on a test laptop configured with an Intel Core i7 Processor, 8 GB DDR4 RAM, and a 512 GB SSD. Your total time may vary slightly depending on your system configurations and internet speed.

Why You Shouldn't Just Use sudo apt install gromacs

Ubuntu's package manager (apt) makes installation simple, but it has two major drawbacks for scientific computing:

  1. Outdated Versions: The repositories often lag months or even years behind the latest stable release.
  2. Generic Compilation: It is built to run on any computer, meaning it won't take advantage of high-performance instruction sets like AVX2 or AVX-512 on modern CPUs, nor will it inherently configure your specific NVIDIA GPU via CUDA.

Compiling from the source code ensures your hardware is fully optimized, saving you days or weeks of calculation time down the line.

Phase One: Installing Prerequisites for GROMACS Installation

Step 1: Update Ubuntu

Before installing any new libraries or packages, ensure your system's package list and existing software are completely up to date. Open your terminal and execute:

sudo apt-get update
sudo apt-get upgrade

Step 2: Install Latest Version of C and C++ Compilers

The latest versions of the C and C++ compilers are typically included by default with Ubuntu. If you want to double-check that the GNU C++ compiler is installed, you can run the command:

sudo apt-get install g++

Step 3: Install Latest Version of Build Essentials

Build Essentials includes the compiler collections and code libraries necessary for compiling software natively on Debian-based systems.

sudo apt install build-essential

Step 4: Install the Correct Version of CMake (Version 3.25 or Higher)

This step is critical and is where most users run into installation errors. By default, older Ubuntu LTS releases (like 20.04 or 22.10) ship with an older CMake version (such as 3.16). GROMACS often requires a newer build tool environment to parse its source files properly.

To fix this, we must first remove the older system version of CMake and replace it with a modern version (like CMake 3.25) using the Snap package manager.

First, purge the old version:

sudo apt remove cmake

Ensure snap is installed on your machine:

sudo apt install snapd

Now, initialize the modern CMake installation:

sudo snap install cmake

Security Warning Notice: Running a standard snap installation for CMake may trigger a security warning asking you to append the --classic flag. The --classic flag is used with the snap install command to install a classic snap, which is a snap that has full access to the system and can run without confinement. Installing a classic snap can potentially pose a security risk, as it can give the snap access to sensitive system resources and data. However, because CMake needs deep access to system directories to build and install GROMACS smoothly, this clearance is required.

Execute the command with the proper privileges:

sudo snap install cmake --classic

Phase one is done! Your core system build environment is officially ready.

Phase Two: Advanced Dependencies & Hardware Preparation

With your compilers and configuration engine locked down, we need to install the mathematical libraries required by GROMACS for parsing Fast Fourier Transforms (FFT) and system interactions.

sudo apt install libfftw3-dev libxml2-dev wget -y

Optional: Set Up NVIDIA GPU (CUDA) Support

If you have an NVIDIA graphics card and want GROMACS to offload heavy force calculations to your GPU cores, you must install the CUDA Toolkit. Skip this step if you are running a CPU-only environment.

sudo apt install nvidia-cuda-toolkit -y

To verify your GPU is actively recognized by the system before proceeding, you can run nvidia-smi in your terminal.

Phase Three: Downloading and Extracting GROMACS Source Code

Next, we navigate to our home directory, download the official source package using wget, and extract it.

cd ~
wget ftp://ftp.gromacs.org/gromacs/gromacs-2023.tar.gz
tar xfz gromacs-2023.tar.gz
cd gromacs-2023

(Note: If you plan on installing a different release variation, simply swap out the 2023 version tags in the commands above to match your specific downloaded source directory).

Phase Four: Compiling and Finalizing the Build

It is standard practice in Linux software engineering to create an isolated build directory. This keeps the original source files pristine and allows you to easily wipe and restart if a configuration parameter needs tuning.

mkdir build
cd build

Now, select one of the following configuration options depending on your available system hardware:

Option A: Configuration for CPU + NVIDIA GPU (Recommended)

cmake .. -DGMX_BUILD_OWN_FFTW=ON -DREGRESSIONTEST_DOWNLOAD=ON -DGMX_GPU=CUDA

Option B: Configuration for CPU-Only

cmake .. -DGMX_BUILD_OWN_FFTW=ON -DREGRESSIONTEST_DOWNLOAD=ON -DGMX_GPU=OFF

What do these flags mean?

  • .. Tells CMake to reference the configuration maps located in the parent folder.
  • -DGMX_BUILD_OWN_FFTW=ON Instructs GROMACS to download and build its own highly optimized version of the FFTW library internally.
  • -DREGRESSIONTEST_DOWNLOAD=ON Automatically downloads a script testing suite to verify GROMACS maps correctly to your hardware before finalizing the install.

Compilation

With the build maps configured, it's time to compile. We tell Linux to use every available processor core on your machine using -j$(nproc) to significantly reduce wait times:

make -j$(nproc)

Once compilation completes without errors, execute the downloaded regression tests to verify calculation accuracy:

make check

(Minor numerical variances here are expected and generally noted as "believed to be harmless".)

System Installation

By default, the compiled binaries will be safely deployed directly into /usr/local/gromacs. Because this path belongs to the system root workspace, you must use sudo privileges:

sudo make install

Phase Five: Environment Automation & Verification

If you try running the command gmx right now, Ubuntu will throw a command-not-found error. This is simply because the system doesn't inherently know where the binary path lives.

GROMACS provides a native shell script called GMXRC to handle environment mapping. We will append an anchor command to your system's .bashrc profile so that GROMACS automatically boots up every single time you spin up a new terminal terminal window:

echo "source /usr/local/gromacs/bin/GMXRC" >> ~/.bashrc
source ~/.bashrc

The Verification Test

Let's make sure the installation executed smoothly and your processor instructions match the compiled code:

gmx --version

Look closely at the command-line readout. It should display your exact version number, confirm whether your CPU's hardware acceleration features (AVX2, AVX-512, etc.) were successfully compiled, and map your graphics card under the hardware log if you chose the CUDA route.

Congratulations! You have successfully built a fully optimized, screamingly fast installation of GROMACS from absolute scratch on Ubuntu. You are now ready to begin preparing your topologies, running energy minimizations, and launching production molecular dynamics trajectories.

Tags: