How to Check RAM Usage in Linux (Beginner’s Guide)

Short Answer

To check RAM usage in Linux, use the following command:

free -h

It shows total, used, and available memory in a human-readable format.

You can also use:

top

or

htop

to view real-time memory usage by processes.


Now let’s understand these commands in detail and explore all the reliable ways to monitor memory usage in Linux from basic terminal commands to advanced tools.


Why Check RAM Usage in Linux?

Monitoring RAM (Random Access Memory) usage helps you:

  • Detect memory-hungry processes
  • Identify performance bottlenecks
  • Optimize applications and servers
  • Prevent system slowdowns or crashes

Whether you’re running Ubuntu, Fedora, CentOS, or Debian — knowing how to check RAM usage is a fundamental Linux skill.


Check RAM Usage Using the free Command

The free command is the simplest and most widely used way to check memory usage in Linux.

Command:

free -h

Example Output:

              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.9G        1.8G        210M        3.0G        4.2G
Swap:          2.0G          0B        2.0G

Explanation:

  • total → Total physical RAM available
  • used → Memory currently in use
  • free → Completely unused memory
  • buff/cache → Memory used by kernel buffers and cache
  • available → Memory available for new processes

The -h flag displays data in a human-readable format (like MB or GB).

Without -h, it shows memory in kilobytes.


Check RAM Usage in Real-Time Using top

The top command gives a live view of system performance — including CPU and memory usage.

Command:

top

Example Output:

MiB Mem :   7849.3 total,   1823.6 free,   2890.2 used,   3135.5 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.

In top, memory usage is shown near the top of the output.

Press q to quit.


Use htop for an Easier, Colorful View (Recommended)

htop is an improved version of top with an interactive, color-coded interface.

Install it first (if not already installed):

For Ubuntu/Debian:

sudo apt install htop

For Fedora:

sudo dnf install htop

For CentOS:

sudo yum install htop

Run it:

htop

You’ll see:

  • Total, used, and available memory bars
  • CPU and swap usage
  • Per-process memory usage
  • Search and sort options

You can scroll or kill processes right from within the tool — making it much easier for live system monitoring.


Check RAM Usage with /proc/meminfo

If you prefer raw data directly from the kernel, check this file:

cat /proc/meminfo

Example Output:

MemTotal:        8029384 kB
MemFree:         1925432 kB
MemAvailable:    4312872 kB
Buffers:          230764 kB
Cached:          2789236 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB

This shows detailed memory statistics including:

  • Total physical RAM (MemTotal)
  • Free memory (MemFree)
  • Cached data (Cached)
  • Swap memory usage (SwapTotal, SwapFree)

You can combine it with grep to simplify:

grep MemTotal /proc/meminfo
grep MemFree /proc/meminfo

Check RAM Usage with vmstat

vmstat (Virtual Memory Statistics) shows memory, CPU, and process info in one place.

Command:

vmstat -s

Example Output:

      8029384 K total memory
      2890232 K used memory
      1925432 K active memory
      4312872 K free memory
       230764 K buffer memory
      2789236 K cache memory

You can also use:

vmstat 2

This updates every 2 seconds — great for tracking changes over time.

If vmstat is missing, install it via:

sudo apt install procps

Using sar Command (System Activity Report)

sar is part of the sysstat package and is useful for tracking historical RAM usage.

Install it:

For Ubuntu/Debian:

sudo apt install sysstat

For Fedora/CentOS:

sudo dnf install sysstat

Command:

sar -r 2 5

This checks memory usage every 2 seconds for 5 intervals.

Output includes:

  • Used and free memory
  • Buffer/cache statistics
  • Swap usage

This is especially helpful for server administrators analyzing performance over time.


Check Memory Usage by Process with ps

To see how much memory each process consumes:

ps aux --sort=-%mem | head

Output Example:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
mysql     1321  3.2 20.4 1802432 825432 ?      Ssl  09:12   1:05 mysqld
firefox   2543  4.5 12.7 2809036 513784 ?      Sl   09:15   2:14 firefox

Here:

  • %MEM → Percentage of RAM used
  • VSZ → Virtual memory size
  • RSS → Resident set size (actual physical RAM used)

Use this to find which applications are using the most memory.


Check Total RAM Installed

To see total physical memory:

grep MemTotal /proc/meminfo

or

sudo dmidecode -t memory | grep -i size

The second command gives hardware-level details about your RAM modules (like total size and slots used).


Check Swap Memory Usage

Swap memory acts as virtual memory when physical RAM is full.

Command:

swapon --show

Example:

NAME      TYPE SIZE USED PRIO
/swapfile file   2G   0B   -2

To check it with free:

free -h

Look under the Swap row.


Combine Commands for Quick Monitoring

Here’s a quick one-liner to see total, used, and free memory together:

free -h && vmstat -s | grep "total memory"

Or a continuous live feed (every 2 seconds):

watch -n 2 free -h

This automatically refreshes memory data every few seconds — great for monitoring in real-time.


Monitor Memory Graphically (GUI Tools)

If you’re using a desktop environment, you can check memory usage without touching the terminal.

For Ubuntu:

Open System MonitorResources tab
You’ll see live graphs for Memory and Swap usage.

For KDE (Plasma):

Open KSysGuard or System MonitorMemory section.

These tools visualize memory usage with graphs and history — useful for beginners and developers.


Example: Diagnosing High Memory Usage

Let’s say your Linux system feels slow. Here’s how you can troubleshoot:

  1. Check overall memory free -h
  2. List top memory-consuming processes ps aux --sort=-%mem | head
  3. Monitor real-time usage htop
  4. Check swap usage swapon --show

If swap usage is high and free memory is low, your system is running out of RAM.
In that case, consider:

  • Closing heavy processes
  • Adding more physical RAM
  • Increasing swap space

Common Commands Summary

TaskCommand
Check total RAM usagefree -h
Real-time memory monitoringtop or htop
Detailed memory infocat /proc/meminfo
Per-process RAM usage`ps aux –sort=-%mem
Memory stats summaryvmstat -s
Historical memory trackingsar -r 2 5
Check total installed RAMgrep MemTotal /proc/meminfo
Check swap memoryswapon --show

Pro Tip: Combine Tools for Deeper Insight

Use htop for live monitoring, free -h for quick snapshots, and /proc/meminfo when you need technical breakdowns.

For production servers, tools like Grafana, Prometheus, or Glances can provide real-time dashboards for memory and CPU tracking.


Wrap Up

Checking RAM usage in Linux is simple once you know the right tools.

If you just need a quick overview:

free -h

If you want a live and colorful view:

htop

And if you need raw technical data:

cat /proc/meminfo

Whether you’re managing a local system or a large-scale server, these commands will help you keep performance under control and troubleshoot memory issues quickly.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *