How to Fix ‘Segmentation Fault (core dumped)’ Error in Ubuntu

Executing a Linux application, compiling software from source, or running automated scripts on Ubuntu only for the process to abruptly terminate with the blunt terminal message: “Segmentation fault (core dumped)” is an iconic Unix failure. Often colloquially shortened to “segfault”, this error occurs at the hardware and operating system boundary. In the Linux virtual memory architecture, the memory management unit (MMU) works with the Linux kernel to assign isolated, virtual memory pages to each running process. When a program attempts to read or write to a restricted memory address (such as dereferencing a NULL pointer), writes to read-only instruction pages, or exhausts its stack frame, the kernel sends a SIGSEGV (Signal 11) termination signal and writes a binary memory snapshot (core dump) to disk. This guide provides actionable methods to inspect core dumps, resolve dynamic library mismatches, and eliminate segfaults in Ubuntu.

Primary Triggers for Segmentation Faults in Ubuntu

While segmentation faults are often software programming bugs, in desktop and server administration they frequently arise from system-level conflicts:

  • Incompatible Dynamic Shared Libraries (.so): Mixing packages from unofficial PPAs, custom builds, or conflicting GLIBC/GCC runtimes causing symbol address mismatches.
  • Physical RAM Hardware Instability: Faulty memory cells, unstable XMP/DOCP memory overclocks, or thermal throttling flipping memory bits during execution.
  • Corrupted Application Binaries: Interrupted package updates or damaged storage sectors corrupting the executable’s ELF header or segment tables.
  • Exhausted Stack Space: Infinite recursion inside user scripts or applications exceeding the default Linux per-process stack size (typically 8 MB).
  • Incompatible Graphics and Display Drivers: OpenGL/Vulkan library conflicts between Mesa and proprietary NVIDIA drivers terminating desktop compositors.

Method 1: Inspect the Crash Backtrace Using coredumpctl and GDB

Modern Ubuntu installations using systemd capture core dumps automatically. Inspecting the crash backtrace pinpoints the exact library or function that triggered the fault.

  1. Open a terminal window (Ctrl + Alt + T).
  2. List the most recent system core dumps:
    coredumpctl list
  3. Identify the crashed executable name and process ID (PID).
  4. Launch the GNU Debugger (GDB) directly on the latest crash dump:
    coredumpctl debug
  5. Once GDB initialises, type:
    bt
    (backtrace) and press Enter.
  6. Review the call stack. The top lines reveal the exact shared library (e.g. libssl.so or libc.so.6) and memory instruction that crashed, telling you which package needs reinstallation. Type quit to exit GDB.

Method 2: Reinstall and Verify Corrupted Packages

If an official Ubuntu utility or service is segfaulting, reinstalling the package restores pristine binaries and configuration files.

  1. Find out which package owns the crashed binary (for example, for git):
    which git && dpkg -S $(which git)
  2. Purge the corrupted package and reinstall it from official repositories:
    sudo apt update && sudo apt install --reinstall <package-name>
  3. Check for broken dependencies across all installed packages:
    sudo apt --fix-broken install

Method 3: Clear LD_LIBRARY_PATH and Remove Conflicting PPAs

Custom library paths can force modern programs to link against outdated legacy libraries stored in /usr/local/lib or user home directories.

  1. Check if custom library paths are active in your environment:
    echo $LD_LIBRARY_PATH
  2. If populated, temporarily unset the variable and run your program:
    unset LD_LIBRARY_PATH && ./your-program
  3. If you recently added third-party PPAs, purge conflicting packages using ppa-purge:
    sudo apt install ppa-purge && sudo ppa-purge ppa:problematic/ppa

Method 4: Test System Memory for Hardware Bit Flips (Memtest86+)

If segfaults occur randomly across different unrelated applications (e.g. GCC, Firefox, and system daemons), defective RAM is the probable culprit.

  1. Reboot your computer and hold Shift (or press Esc) to bring up the GRUB bootloader menu.
  2. Select Memory test (memtest86+) from the boot menu.
  3. Allow Memtest86+ to execute at least one complete pass (this takes 30 to 60 minutes).
  4. If any red error lines appear indicating address verification failures, one of your physical RAM sticks is defective and must be replaced.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.