5 ways to check available memory in Ubuntu 20.04

s2 0

As Ubuntu users, especially administrators, we need to check how much RAM resources our system is using and how much of it is free. We also know that most administration-related tasks are better done from the Linux command line than from the graphical user interface. For example, servers normally operate on the shell and no GUI is available at all. Since the most important thing is to control the storage resources on the servers, the best thing to do is to learn the appropriate commands that can help us with server administration.

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

  • The free command
  • The vmstat command
  • The / proc / meminfo command
  • The top command
  • The htop command

With these commands you can always be sure that there are enough memory resources available for the very important processes on your servers. For example, if you run 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 20.04 LTS system.

To see the memory usage we will use the Ubuntu command line, the Terminal application. You can open the terminal either via the system bar or the key combination Ctrl + Alt + T.

Method 1: the free command

Since the free command is the most widely used and undoubtedly the most helpful, we’ll mention its use first. This command is used to check information about your system’s RAM usage. Here is the command you enter in the terminal:

$ free -m

The flag m means that the information is displayed in MB.

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

Method 2: the vmstat command

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

$ vmstat -s

The s flag provides detailed statistics on memory usage.

You can view the free memory and the free swap memory entry in the output to see the available memory on your system.

Method 3: the / proc / meminfo command

The following command extracts storage-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

Use / proc / meminfo to get details about memory usage

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

Method 4: the top command

The top command is used to print your system’s CPU and memory usage. You can just use this command like this:

$ top

Use the top command for memory usage

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

Method 5: the htop

Just like the top command, the htop command provides a detailed analysis of your CPU and memory usage. If you don’t 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 typing the following command as sudo:

$ sudo apt install htop

Use the htop command

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

$ htop

Use the htop command

the memo (Memory aka RAM) and Batch (Swap) entries in the header indicate the used and total memory, which you can use to calculate the free memory of your system.

You can use the commands we mentioned in this article to monitor that your system processes are never running out of memory. You can avoid the GUI altogether and still keep an eye on the memory usage on your PCs and servers.

5 ways to check available memory in Ubuntu 20.04