The Vagrant box that we pick will default to some amount of RAM. During our development, we’ll run into situations where we need to increase that amount. To do that we’re going to introduce a new section that’s specific to VirtualBox. We can then set the amount of RAM (in Megabytes) using the
memory configuration setting.
Vagrant.configure("2") do |config| config.vm.box = "generic/ubuntu2004" config.vm.provider "virtualbox" do |vb| # Customize the amount of memory on the VM: vb.memory = "4096" end end
The fun part about this setting is that because we’re configuring resources for a VM and not a physical device we can easily give it memory amounts that would be hard to get into a physical device. For example, we could give our VM 3GB of RAM.
Vagrant.configure("2") do |config| config.vm.box = "generic/ubuntu2004" config.vm.provider "virtualbox" do |vb| # Customize the amount of memory on the VM: vb.memory = "3072" end end
Now if reload our VM and ssh into it we can check and see we now have 3 GB of RAM.
$ free -mh total used free shared buff/cache available Mem: 2.9Gi 452Mi 2.2Gi 3.0Mi 328Mi 2.3Gi Swap: 1.9Gi 0B 1.9Gi
If you have questions related to vagrant or the PHP ecosystem in general you would like us to answer in future videos please ask them in the comments below.
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
More In This Series
- What's a Virtual Machine?
- Why Use Vagrant?
- Initializing a Vagrant Development Environment
- Managing A Vagrant Environment's Power State
- How to Reset/Delete A Vagrant Development Environment
- Configuring Our Vagrant Development Environment's Network
- Remotely Accessing Our Vagrant Development Environment (Linux/Ubuntu)
- Syncing Files to Our Vagrant Development Environment
- Customizing the Amount Of RAM in Our Vagrant VMs
- Displaying Our Vagrant VMs User Interface