Categories: LinuxUbuntu

5 Ways to Check Available Memory in Ubuntu 22.04

As Ubuntu users, especially administrators, we need to check how much RAM resources our system uses and how much 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, with no graphical user interface. Since controlling the memory resources on servers is most important, it is best to learn the appropriate commands to help us manage servers.

In this article, we will explain how you can check the available memory using the following five 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.

We use the Ubuntu command line and Terminal application to view memory usage. You can open Terminal using 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.

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

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.

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

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 use this command as follows:

$ top

In the output header, 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

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 install htop by entering the following command as sudo:

$ sudo apt install htop

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

$ htop

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.

Vitux Staff

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago