LAMMPS from scratch · 25 min

Building LAMMPS from source

Compiling LAMMPS yourself takes four commands. We did it on a small computer and show the real output of every step: how long it took, what each line means, how to add a package, and the three errors beginners meet most. The proof that it worked is, again, the melt step-0 line matched by hand.

1 · Understand: what you need

Building means running the compiler on the LAMMPS source (page 0.1). Four tools do the work. Check that each one answers in your terminal (page 0.2):

ToolCheck withWhat it doesOurs
gitgit --versiondownloads the source2.43.0
CMake, at least 3.16cmake --versionreads your choices and writes the build instructions3.28.3
a C++ compilerg++ --versionturns the source into a program (C++17 preferred, C++11 the minimum)GCC 13.3.0
MPI (optional)mpirun --versionlets one run use many processorsMPICH

On Ubuntu one command installs all four: sudo apt install git cmake g++ mpich. On macOS, xcode-select --install and then brew install cmake open-mpi. On Windows, do this inside Ubuntu for Windows (WSL).

2 · The four commands, with our real output

Step 1: download exactly the version this course quotes (the newest is stable_30Sep2026):

git clone -b stable_22Jul2025_update6 --depth 1 https://github.com/lammps/lammps.git cd lammps

Step 2: configure. Make a separate folder for the build, then tell CMake where the instructions are (the cmake folder) and which packages you want:

mkdir build cd build cmake ../cmake -D PKG_MOLECULE=yes -D PKG_KSPACE=yes -D PKG_RIGID=yes

CMake checks your computer and prints a summary. These are the lines worth reading in ours:

-- Found MPI: TRUE (found version "5.0") found components: CXX MPI found: parallel runs possible LAMMPS Version: 2025.7.22.6 stable_22Jul2025_update6 the version you asked for Build type: Release full optimisation -- Enabled packages: KSPACE;MOLECULE;RIGID your package choice C++ Standard: 17 the compiler is modern enough C++ Flags: -O3 -DNDEBUG -O3: optimise for speed

A ready-made choice also exists: cmake -C ../cmake/presets/basic.cmake ../cmake switches on KSPACE, MANYBODY, MOLECULE and RIGID.

Step 3: compile. -j 2 uses 2 processors at once; use the number your computer has.

make -j 2 [ 8%] Building CXX object CMakeFiles/lammps.dir/…/src/angle_deprecated.cpp.o [ 9%] Building CXX object CMakeFiles/lammps.dir/…/src/angle.cpp.o … 451 files, one line each [100%] Linking CXX static library liblammps.a [100%] Linking CXX executable lmp [100%] Built target lmp done: 266 s on 2 processors

Step 4: test. The new program is the file lmp in the build folder, so run it as ./lmp:

./lmp -h | head -3 ./lmp -in ../examples/melt/in.melt Step Temp E_pair E_mol TotEng Press 0 3 -6.7733681 0 -2.2744931 -3.7033504

3 · Match: is the build right?

A program that compiles can still be wrong (a bad compiler flag, a broken library). The step-0 line is a test with a known answer, worked out by hand on the Start page. Paste your build's line:

(the box holds our line; replace it with yours)

4 · Modify and observe: add a package

Our build stopped at pair_style tersoff: that force belongs to the MANYBODY package. Adding a package means configuring again (the dot means "this build folder") and compiling again:

cmake -D PKG_MANYBODY=yes . make -j 2
beforeafter adding MANYBODY
installed packagesKSPACE MOLECULE RIGIDKSPACE MANYBODY MOLECULE RIGID
pair styles available5291
size of lmp11.6 MB12.8 MB
files compiled451 (from nothing)489 (almost everything again)
time on 2 processors266 s274 s
melt step 0−6.7733681−6.7733681 (unchanged)

Why compile almost everything again, when only 39 new files were added? Many core files read small generated lists of "which styles exist" and "which packages are installed". Adding a package changes those lists, so every file that reads them must be compiled again. Changing one existing file (page 0.1: 3.8 s) is cheap; changing the package list is not. Choose your packages before starting long work.

5 · The three errors beginners meet most

You seeWhyFix
CMake Error: The source directory "…/lammps" does not appear to contain CMakeLists.txt.cmake was pointed at the lammps folder; its instructions are in lammps/cmakecmake ../cmake from inside lammps/build
make: *** No targets specified and no makefile found. Stop.make was run before cmake, or in the wrong folderrun cmake first, then make, both inside build
ERROR: Unrecognized pair style 'tersoff' is part of the MANYBODY package which is not enabled in this LAMMPS binary.the input uses a package you did not buildcmake -D PKG_MANYBODY=yes . then make

All three messages above are copied from our own terminal.

Your turn

1. Your computer has 8 processors. Roughly how long should the build of section 2 take, if 2 processors took 266 s?

2. You edit one line in src/pair_lj_cut.cpp and type make -j 2. Will it take 266 s again?

3. After adding MANYBODY, why must melt still print E_pair = −6.7733681?