5 Ways to Check Available Memory in Ubuntu 22.04 linux ubuntu

As Ubuntu users, especially as administrators, we need to check how much RAM resources our system uses and how much of it is free. We also know that most administrative tasks are better done from the Linux command line than from the graphical user interface. For example, servers usually work on the shell, and there is no graphical user interface at all. Since it is most important to control the memory resources on servers, it is best to learn the appropriate commands that can help us manage servers.

In this article, we will explain how you can check the available memory using the following 5 commands:

  1. free command
  2. vmstat command
  3. /proc/meminfo command
  4. top command
  5. htop command

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

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

To view memory usage, we use the Ubuntu command line, Terminal application. You can open Terminal using either the system dash or the Ctrl alt T key combination.

Method 1: The free command

Since the free command is the most widely used and without any doubt the most helpful, we will mention its usage first. This command is used to check information about the RAM usage by your system. Here is the command you will enter in the Terminal:

$ free -m

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

<img alt="Ubuntu free command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-27.png62625e924873f.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="113" loading="lazy" src="data:image/svg xml,” width=”733″>

The available column indicates the available memory. The used column in the swap entry is also 0 which means that it is all unused and thus free.

Method 2: The vmstat command

In order to view memory statistics through the vmstat command, you can use it in the following manner:

$ vmstat -s

The s flag provides detailed statistics about memory usage.

<img alt="Check memory with vmstat command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-28.png62625e9261115.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="467" loading="lazy" src="data:image/svg xml,” width=”495″>Advertisement

You can view the free memory and the free swap memory entry in the output, indicating the available memory in your system.

Method 3: The /proc/meminfo command

The following command extracts memory-related information from the /proc file system. These files contain dynamic information about the system and the kernel rather than the real system files.

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

$ cat /proc/meminfo

<img alt="Use /proc/meminfo to get memory usage details" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-29.png62625e92749d1.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="537" loading="lazy" src="data:image/svg xml,” width=”393″>

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

Method 4: The top command

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

$ top

<img alt="Use top command for memory usage" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-30.png62625e927a757.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="236" loading="lazy" src="data:image/svg xml,” width=”771″>

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

Method 5: The htop command

Just like the top command, the htop command also gives a detailed analysis of your CPU and memory usage. If you do not have installed htop on your system, you can install it by first updating your abt repositories through the following command:

$ sudo apt-get update

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

$ sudo apt install htop

<img alt="Use htop command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-31.png62625e9281eba.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="340" loading="lazy" src="data:image/svg xml,” width=”489″>

Once htop is installed, you can simply use the following command to print the required information:

$ htop

<img alt="Use htop command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-32.png62625e928adff.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="438" loading="lazy" src="data:image/svg xml,” width=”1077″>

The Mem (Memory aka RAM) and Swp (Swap) entries in the header indicate the used and total memory through which you can calculate the free memory available on your system.

With the commands that we have mentioned in this article, you can monitor that your system processes are never out of memory. You can avoid the GUI altogether and still keep a check on memory usage on your personal computers and servers.