Linux Commands

How to check RAM in a Linux

RAM stands for Random Access Memory considered as an important part of any computer system. When you open a file for editing or viewing its content, the system creates a temporary instance of this particular file in RAM so that you can do processing on it. Moreover, your system’s operating environment and RAM act as a medium on which you run a program. If you have a fresh Ubuntu operating system or VPS (Virtual Private Server) and you don’t have enough information about RAM, how much it is installed and used, the RAM speed, then this article is written for you.

In this article, we will show you how to check how much RAM or memory is installed on your Linux system and how to check its speed. We have implemented all the commands on Ubuntu 20.04 operating system. Let’s get started!

As we mentioned above, we will work on Ubuntu 20.04 command-line environment. Therefore, we need to open the Terminal application to explain RAM monitoring tasks. The terminal window can be accessed either using the Ubuntu Application launcher search bar or you can launch it through the Ctrl+Alt+T shortcut.

Check RAM Size and Availability

Using the following command, you can check how much RAM is installed on your Ubuntu 20.04 system:

$ free

The above command is used to check memory and swap utilization on your system in a few lines. If you will not use any switch, then the output to be printed in kilobytes.

It is better to use switch -h along with the free command that shows the installed RAM and swap utilization in 3 nearest possible digit format.

$ free -h

The highlighted part ‘Mem’ in the above image provides you the complete information about the RAM on your system. The ‘total’ column shows you the installed RAM in GBs on your system. The available and columns represent the available free GBs for use and about the RAM that how much is used in your system respectively.

The -s switch allows free to run continuously for seconds, it shows a new output after the specified number of seconds.

For example, we want to execute the free command for every 3 seconds then we will use the following command:

$ free -s 3

Check RAM usage with top command

The top command displays all information about memory utilization for each process on your system. This command is preinstalled on every Linux system. But if it is not available you can install it using the apt command. You can run the top command on your system as follows:

$ top

Observe the %mem column. If you want to view a process that is utilizing much memory then, press Shift+m. It will sort the programs based on the memory usage on top. This is the benefit of this command that you can monitor the memory usage of your system at a quick glance. Press q to exit from the top menu.

Check RAM usage with htop command

The htop command displays the overall information about RAM utilization in which it continuously updates the statistics and shows you how much memory is used by each process.

Unlike free commands, the htop utilities are often not installed on Linux systems by default. However, you can install it by using the following commands on the terminal:

$ sudo apt install htop

Once the installation is completed, you can run it through the terminal.

$ htop

Press the F6 key to sort the memory utilization output. Under the %mem column, you can monitor the memory statistics. To exit from the current htop menu press ‘F10’.

Htop is a free ncurses-based process GPL viewer for all Linux distributions. It is quite similar to the top command, but the htop command also allows you to scroll horizontally and vertically, so it gives the complete information along with their full command lines about all the processes that are running on the system.

Check RAM using /proc/meminfo

You can take the memory-related information from the /proc file system. These files keep the dynamic information about the system and kernel.

Run the following command to display the memory information:

$ cat /proc/meminfo

Check RAM type and Speed

Different types of RAM are available in the market in which DDR1, DDR2, DDR3, and DDR4. DDR, SDRAM, and DRAM were included. The speed of a RAM we take in terms of cycles means how much cycles are completed in one second.

$ sudo dmidecode --type memory | less

Using the above command, you can check RAM type and speed. Use arrows keys to navigate between the displayed options.

Conclusion

In this article, we have shown the implementation of different commands that are very useful for checking your system’s RAM. Moreover, you can also detect RAM error using the memtester and memtest utility which has already been covered in the previous article. So, all of the above commands are important for every Linux user. That’s all about monitoring your RAM. Please give us your suggestions or send queries via the comments.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.