Skip to main content
How To

How to Check RAM in Ubuntu Command Line

Learn how to check the total and free size of RAM in Ubuntu. Also learn to check the hardware characteristics of RAM in your system.


As someone who manages Ubuntu servers, you'll need to know how much RAM your system has, and how much of the RAM is free to use. You may even want to check the kind of RAM it is (DDR1 or DDR2).

In this tutorial, I'll show you how you can achieve the following in the terminal:

  • Check the total RAM size
  • Check the used and free RAM
  • Type and speed of RAM

Check the total RAM size and the free RAM

You can use the free command to display the amount of free and used memory (RAM) in the system.

free -h

The -h option displays the output in a human-readable format. This means that you get to see the RAM size in GB, MB etc instead of in bytes.

You should see an output like this:

root@learnubuntughost:~# free -h
              total        used        free      shared  buff/cache   available
Mem:          1.9Gi       669Mi       726Mi       1.0Mi       587Mi       1.1Gi
Swap:            0B          0B          0B

You have to focus on the Mem row and the total and available columns.

Check RAM in Ubuntu command line

As you can see, my Ubuntu server (running this site) has 1.9 GB of total RAM and 1.1 GB of available RAM. This available RAM is the free RAM your system can use.

If your system is often running out of available RAM, you should consider adding swap space to your Ubuntu machine.

Notice the free column? Free memory is the amount of RAM which is currently not used for anything. The available memory is the amount of RAM available for new or existing processes.

1.9 GiB of RAM sounds strange, isn't it? Should it not be 2 GB?

It depends on your definition of GB. For a long time, we were taught that things move in the power of 2 (binary) in the computing world. 1 KB is 1024 bytes (2 to the power 10). 1 MB is 1024 kilobytes.

But things have changed lately. The SI units use decimal for the size calculation. In this method, a kilo is 1000. So a kilobyte is 1000 bytes, a megabyte is 1000 kilobytes and a gigabyte is 1000 megabytes.

So, to keep a distinction, GB (Giga Byte) is now calculated in decimal (in the power of 10). And the actual binary computing unit (in the power of 2) is changed to GiB (Gibibye).

So, when I deployed a server with 2 GB of RAM, it got me only 1.86 GiB. The free -h rounded up the numbers and hence it shows 1.9 GiB.

Use Free Command in Ubuntu
The free command lets you see your Ubuntu system’s current RAM usage. Learn how to use the free command.

Check free RAM in real-time

If you want to keep a tab on the memory usage, you can combine the watch and free command.

watch free

This will change the output of the free command after every 2 seconds.

Watch RAM usage in real time

To stop the continuously running command, press Ctrl+C.

An alternative and in my opinion better way is to the top command. Not only does it show the total memory usage in real-time, but it also shows the memory consumption by various processes.

Just run the command in the terminal:

Check RAM in real time with top command in the terminal

By default, the top command output is sorted by CPU consumption. You can press Shift+M to sort top command by memory.

To exit the top command, press the Ctrl+C keys.

That's enough discussion on the memory unit. Let's see how can you see what type of RAM your system has.

Check Number of CPU Cores in Ubuntu
Learn various ways to check the number of CPU cores in Ubuntu command line.

Check the type and speed of RAM

The dependable DMI table decoder command dmidecode gives you all kinds of information about your system's hardware.

To see the RAM details, you should filter its output on the memory like this:

sudo dmidecode --type memory

Yes, you need to use sudo or be root to use this command.

You should see a long output. You'll see part of the output is repeated for each core of processors you have. My system in the example has 8 cores and it repeats the same for 8 times.

# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 3.2 present.

Handle 0x1000, DMI type 16, 23 bytes
Physical Memory Array
	Location: System Board Or Motherboard
	Use: System Memory
	Error Correction Type: None
	Maximum Capacity: 16 GB
	Error Information Handle: Not Provided
	Number Of Devices: 8

Handle 0x1100, DMI type 17, 84 bytes
Memory Device
	Array Handle: 0x1000
	Error Information Handle: Not Provided
	Total Width: 16 bits
	Data Width: 16 bits
	Size: 2 GB
	Form Factor: Row Of Chips
	Set: None
	Locator: Motherboard
	Bank Locator: Not Specified
	Type: LPDDR4
	Type Detail: Synchronous
	Speed: 4267 MT/s
	Manufacturer: Not Specified
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified
	Rank: 1
	Configured Memory Speed: 4267 MT/s
	Minimum Voltage: Unknown
	Maximum Voltage: Unknown
	Configured Voltage: 0.6 V
	Memory Technology: DRAM
	Memory Operating Mode Capability: Volatile memory
	Firmware Version: Not Specified
	Module Manufacturer ID: Bank 1, Hex 0x2C
	Module Product ID: Unknown
	Memory Subsystem Controller Manufacturer ID: Unknown
	Memory Subsystem Controller Product ID: Unknown
	Non-Volatile Size: None
	Volatile Size: 2 GB
	Cache Size: None
	Logical Size: None

What you need to focus here is the total size (you already know), speed and type of RAM.

Type and speed of RAM in Ubuntu command line

As you can see in the screenshot above, I have LDDR4 RAM with 4276 MT/s of speed.

More on that

That was good, right? Now you know how to check RAM size in the Ubuntu command line. You also learned to check memory usage in real time.

In related posts, you can learn about listing the disks and drives in Ubuntu.

How to List Drives in Ubuntu Command Line
Wondering what partitions and drives are on your Ubuntu system? Here are various ways to list the drives on Ubuntu.

Or, check free disk space on your Ubuntu system.

Check Disk Space in the Ubuntu Command Line
Wondering what’s the disk size? How much free space you have left? Learn about checking disk space in the Ubuntu command line.

If you have any questions or suggestions, let me know in the comments.