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.
- The four commands that download, configure, compile and test LAMMPS
- How to read the configuration summary and the list of installed packages
- Why adding a package means compiling almost everything again, measured
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):
| Tool | Check with | What it does | Ours |
|---|---|---|---|
| git | git --version | downloads the source | 2.43.0 |
| CMake, at least 3.16 | cmake --version | reads your choices and writes the build instructions | 3.28.3 |
| a C++ compiler | g++ --version | turns the source into a program (C++17 preferred, C++11 the minimum) | GCC 13.3.0 |
| MPI (optional) | mpirun --version | lets one run use many processors | MPICH |
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):
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:
CMake checks your computer and prints a summary. These are the lines worth reading in ours:
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.
Step 4: test. The new program is the file lmp in the build folder, so run it as ./lmp:
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:
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:
| before | after adding MANYBODY | |
|---|---|---|
| installed packages | KSPACE MOLECULE RIGID | KSPACE MANYBODY MOLECULE RIGID |
| pair styles available | 52 | 91 |
| size of lmp | 11.6 MB | 12.8 MB |
| files compiled | 451 (from nothing) | 489 (almost everything again) |
| time on 2 processors | 266 s | 274 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 see | Why | Fix |
|---|---|---|
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/cmake | cmake ../cmake from inside lammps/build |
make: *** No targets specified and no makefile found. Stop. | make was run before cmake, or in the wrong folder | run 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 build | cmake -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?
make -j 8.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?
pair_style lj/cut, which did not change. Adding a package adds new styles but must not change existing ones. If step 0 changed, something in the build would be broken.