How to free up RAM in Ubuntu

Free RAM memory in Ubuntu

It has always been said that the RAM is there to use it. Of course, this is valid when we have a computer with enough memory to not be watching what happens with it. When we're a little tighter, it's worth taking care of it a bit, in the sense that we have to watch how busy we are and, whenever possible, make sure our team can get some air.

Sometimes, the system does not release RAM memory that is no longer being used and although it is released on demand —to call it somehow— when we open a new program, it can also be released manually by entering a simple command in our console. In theory, this behavior is common in almost all operating systems, and it makes sense: to be able to go faster when we want to access something we just used again.

Find out how much is in use and then free up RAM

First of all, stop know how much memory is in use, how much is free and how much is saved in the cache we execute the command:

free -m

To see the use in real time we use:

watch -n 1 free -m

The first command will return something similar to what we see in the header capture, while with the second we will see something very similar, but it will move in real time.

As can be seen, there is a large amount of cached memory, about half of which is being used by open applications. For release cached pages, inodes, and directory entries, just run the command:

sudo sync

Followed by:

sudo sysctl -w vm.drop_caches=3

It is important not to forget to run "sudo sync", or else we could lose information present in RAM that has not yet been saved to the hard drive.

Closing unnecessary processes

Ubuntu, and Linux in general, manages RAM pretty well, so you usually don't need to do any of the above. It can be different if the operating system does not know what to do with a heavy workload. That is to say, when we have many programs open, the operating system cannot or is not the one to decide what to do with each of them, and it tries to move them as it can. If there is no RAM, it will probably "decide" on its own to close some program, but this can cause us to lose some information.

Therefore, and as on so many occasions, the best way to manage RAM memory is head. If we have a computer with at least 16GB of RAM, we will rarely run out of memory if we do it in normal use, but with 4 or less, things are different. In these cases, it is best to have open only what is necessary.

If we notice that the computer suffers, we can open the task manager and see what is happening:

Ubuntu System Monitor

In the system monitor, a graphical tool (GUI) that shows us information similar to that of htop, we will see all the processes that are open. We can order them by name, by user, CPU or RAM usage, among others. If we notice that our computer is slow or has a hard time working, we are interested in ordering the processes by processor use (% CPU) or RAM (Memory). If we know what a process that is consuming a lot of resources is doing, we can right-click on it and choose the “Kill” option. Of course, saving before all the important changes.

If you look closely at the information offered by the system monitor or htop, among others, we will learn what consumes the most. From here, a recommendation for the owners of a low-income equipment is that have a good control of the web browser. Although it can be used to do everything and today it is one of the best work tools, it can also have many open processes that can leave our computer speechless. Therefore, it is worth not having many tabs open if they are not needed, and even closing the browser entirely.

RAM is there to use it, but not to waste it or make us suffer.

More information - Check the temperature of your computer with the command 'sensors'

The content of the article adheres to our principles of editorial ethics. To report an error click here.

10 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Miquel Mayol i Tur said

    There is an elatareao script that can be found on your page called that frees the cache if it occupies 90% of RAM.

  2.   Christian yones said

    And what is gained by freeing the memory used for cache? We force the machine to reread many things from the disk that it already had in memory. The machine will run slower until the cache is refilled ...

  3.   Santiago Jose Lopez Borrazas said

    Do not give yourself so much in the head. The Linux kernel takes care of freeing up that remaining memory. I don't see any sense.
    I don't even use that implementation, because in fact, as Cristian Yones says, it is better not to use that, because you will end up rewriting the hard disk for so long.
    It is better to have it as we have said. Do not touch anything.

  4.   Mario Arleth Orozco Gil said

    In my case it worked perfectly. Since I have a server with asterisk in which calls are made. I had consumed almost 16 gigs of ram out of the 16 available and my load was increasing. When running the procedure, it freed up my memory and left an average of 5gb consumed, allowing the system to have ram memory available for any task and to improve the performance of the machine. Thanks for the solution. Perhaps as Santiago says, it is not always useful, but in my case it was.

  5.   gasdononay said

    Great solution, especially if we want to copy files that weigh 5, 10, 20, 30 GB, ...
    Thank you very much and greetings

  6.   Manuel Muñiz Lake said

    It has served me, thank you.

  7.   barinascode said

    It always works for me, since I do tests on virtual servers with 500 mb of ram

  8.   javier renteria said

    well ... from what I understand more useful for when you are going to work with large files ...
    in my case it is not necessary .. in the same way thanks for sharing

  9.   paul chivel said

    Hello, I don't get command 1, what do I do?

  10.   paul chivel said

    Hello to me, the first command is not working