5 Ways to Check Available Memory in Ubuntu 20.04

As users of Ubuntu, especially as administrators, we must check how much RAM our system uses and how many of them are free. We also know that most administrative tasks can be done better using the Linux command line than through the graphical user interface. For example, servers usually work in a shell, and the graphical interface is generally not available. Since it is most important to control memory resources on servers, it is best to learn the appropriate commands that can help us administer the server.

This article explains how to use the following 5 commands to check available memory:

  • Free team
  • Vmstat team
  • Command / proc / meminfo
  • Top team
  • Htop command

Using these commands, you can always be sure that enough memory resources are available for very important processes running on your servers. For example, if you are working with a web server, you can be sure that lack of resources will not slow down access to the website or even cause the website to crash.

We ran the commands and procedures mentioned in this article on the Ubuntu 20.04 LTS system.

To display memory usage, we use the Ubuntu command line, Terminal application. You can open a terminal using the system bar or the key combination Ctrl + Alt + T.

Method 1: Free Team

Since the free command is the most widely used and, without a doubt, the most useful, we will first mention its use. This command is used to check the memory usage information of your system. Here is the command you enter in the Terminal:

$ free -m

The m flag means that the information will be displayed in megabytes.

The available column shows the available memory. The column used in the swap record is also 0, which means that it is not used and therefore free.

Method 2: vmstat command

To view memory statistics using the vmstat command, you can use it as follows:

$ vmstat -s

The s flag provides detailed memory usage statistics.

Check memory with vmstat command

You can view information about free memory and free swap memory on the output, indicating the available memory on your system.

Method 3: the command / proc / meminfo

The following command retrieves memory related information from the / proc file system. These files contain dynamic information about the system and the kernel, and not about real system files.

This is the command you will use to print memory information:

$ cat /proc/meminfo

Use / proc / meminfo for memory usage information.

The output of this command is similar to the vmstat command. You can easily view free memory as a result of MemFree and free swap memory as a result of SwapFree.

Method 4: top command

The top command is used to print the processor and memory usage of your system. You can simply use this command as follows:

$ top

Use the top command to use memory

In the header of the output, you can see the KiB Mem and Kib Swap entries, with which you can check the used and free memory resources.

Method 5: htop command

Like the top command, the htop command also provides a detailed analysis of your processor and memory usage. If you do not have htop installed on your system, you can install it by first updating your abt repositories with the following command:

$ sudo apt-get update

And then install htop by entering the following command as sudo:

$ sudo apt install htop

Use the htop command

After installing htop, you can simply use the following command to display the necessary information:

$ htop

Use the htop command

Mem (Memory aka RAM) and SWP Records (swaps) in the header indicate the used and shared memory through which you can calculate the amount of free memory available on your system.

Using the commands that we mentioned in this article, you can ensure that your system processes never remain in memory. You can avoid the graphical interface altogether and still monitor memory usage on your personal computers and servers.

5 Ways to Check Available Memory in Ubuntu 20.04

Sidebar