Home Linux How To Increase Memory And CPU On Vagrant Machine
Increase Memory And CPU On Vagrant Machine In Linux

How To Increase Memory And CPU On Vagrant Machine

By sk
3501 Views

Having performance issues with your Vagrant machine? It is probably because of insufficient Memory or CPU. Simply add more RAM and CPU core to Vagrant machine to improve its performance. This brief guide explains how to increase Memory and CPU on Vagrant machine in Linux from commandline.

The other day I noticed that the dnf package manager keeps getting terminated immediately when I run any package management operations, such as update, install, remove etc., in my Fedora vagrant virtual machine I can't even update the repository lists.

dnf command killed
dnf command killed

Initially, I thought this issue is related to OS. After couple investigations, I found that the Memory size of the Fedora VM is very low (512 MB to be precise). So I decided to add more memory and the CPU count to my Fedora Vagrant machine. It worked just fine as expected.

Now let us go ahead and set sufficient Memory size and CPU counts to a VM from commandline.

Increase Memory and CPU on Vagrant machine from commandline

When you initialize a new vargant environment, a configuration file named Vagrantfile is created. This file contains the details of operating system and software requirements. The actual purpose of a vagrantfile is to describe the type of the virtual machine and how to configure and provision the VMs.

To add memory and CPU to a Vagrant virtual machine, edit Vagrantfile:

$ vi Vagrantfile

Define the RAM size and CPU count like below.

config.vm.provider "virtualbox" do |v|
  v.memory = 2048
  v.cpus = 2
end
Define RAM size and CPU count in Vagrantfile
Define RAM size and CPU count in Vagrantfile

As per the above configuration, I have defined 2 GB RAM and 2 CPU core to my Vagrant machine. Make sure you have added these lines before the last "end" line. Save the file and exit.

Now start the Vagrant machine. If the Vagrant machine is already running, just reload it to take effect the changes.

$ vagrant reload

Check the RAM size with command:

$ free -h

Samle output:

               total        used        free      shared  buff/cache   available
 Mem:          1.9Gi       100Mi       1.7Gi       5.0Mi       153Mi       1.7Gi
 Swap:            0B          0B          0B

Check the total number of CPU cores using command:

$ nproc 
2
Check RAM size and CPU core count in Linux
Check RAM size and CPU core count in Linux

As you see in the above output, the RAM size is 2 GB and the CPU count is 2.

There are many ways to find the number of CPU cores. The following guide lists more ways to find the number of CPU cores:

This is how we can set Memory size and CPU count for a Vagrant machine in Linux. We can do more customization through Vagrantfile. I will publish more Vagrant tips in the days to come. Stay tuned!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More