Do you want to know how to check the RAM or swap memory of your linux computer? In this article, first we discuss the terminology of memory in linux system and then we move on to talk about how to check them.
What is RAM?
RAM is a primary memory of a computer. It is used to run applications and store temporary data on your computer. It is also called Physical Memory. RAM is volatile in that the data stored in RAM will be lost once the system is turned off.
Swap memory
Swap memory is used when RAM is full. If the system needs more memory for active processes but the RAM is full, inactive pages will be moved to Swap memory. However swap memory should not be considered a replacement for RAM.
How to check memory in linux
Now that we have the basic understanding of memory, let's dive in to the actual commands you use to check the memory.
One of the easiest ways to visualize memory is free command,
free
This command will show the total amount of memory, how much is used and how much is still available.
To make it visually easy to see, you can use the -h option,
free -h
By adding -t option, you can get the totals of RAM and swap
free -h -t
You can also use top command to get the detailed information of memory usage.
top
press SHIFT + M key to sort the order by momory
Conclusion
Free command and top command are two useful tools when investigating memory usage. These are extremely powerful and helps you a lot. The reason I wrote this article is when compiling npm I got an error and it turned out to be due to the lack of memory. Hope this article was helpful.