How to Check RAM Usage in Ubuntu Terminal

If your Ubuntu server suddenly becomes unresponsive, or if a specific database application starts crashing unexpectedly, the most likely culprit is a lack of available memory (RAM). When a Linux system completely exhausts its physical memory, it is forced to write temporary data to the much slower hard drive (the swap file), bringing system performance to a crawling halt.

Before you reboot the server or attempt to kill random processes, you must accurately diagnose the current memory pressure. Unlike a desktop computer, you do not have a graphical Task Manager. Instead, you must use the command line.

The ‘free’ Command

The absolute fastest and most reliable way to check your total and available RAM in Ubuntu is the free command.

  1. Open your terminal or SSH into your Ubuntu server.
  2. Type the following command and press Enter:
free -h

Why use the ‘-h’ flag?
By default, the free command outputs the memory data in bytes, resulting in a confusing string of massive numbers (e.g., 8388608). The -h flag stands for “human-readable.” It automatically converts the math into Gigabytes (G) or Megabytes (M), making the output instantly understandable.

Understanding the Output

The terminal will print a small grid containing two rows: Mem (your physical RAM) and Swap (your overflow hard drive memory). The columns break down exactly how that memory is being utilized.

  • total: The absolute maximum amount of RAM installed in the server (e.g., 16G).
  • used: The memory currently actively dedicated to running applications (e.g., Nginx, MySQL, or Python scripts).
  • free: Memory that is completely unallocated and doing absolutely nothing. (Do not panic if this number is very low; Linux intentionally keeps this number low).
  • buff/cache: This is the secret to Linux performance. The operating system intentionally uses almost all of your “free” memory to aggressively cache files and speed up the system. If an application suddenly demands more RAM, Linux will instantly dump this cache and hand the memory over to the app.
  • available: This is the most important column. This is the true, accurate estimate of exactly how much RAM is realistically available for starting new applications before the system begins to struggle.

The ‘htop’ Command for Real-Time Monitoring

The free command takes a static snapshot of your memory at the exact second you press Enter. If you are trying to monitor a memory leak while actively using an application, a static snapshot is not helpful.

Instead, use the htop command. (If it is not installed, run sudo apt install htop first).

htop

This command launches a beautiful, color-coded, real-time dashboard directly inside your terminal window. The top-left corner will display a visual bar graph (labelled Mem) that fills up and changes colors dynamically as your RAM usage fluctuates second by second. When you are finished monitoring the system, press the q key on your keyboard to quit the dashboard and return to the normal command prompt.

Get the best tech tips delivered straight to your inbox.

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