DEV Community

Morodolu Oluwafikunayomi
Morodolu Oluwafikunayomi

Posted on

Spin Up, Explore, and Destroy: A Complete Beginner’s Guide to Using Vagrant with Ubuntu (Visual Walkthrough)

Prerequisites
Before we begin, make sure you have:

  • Vagrant installed → Download here
  • VirtualBox (or any supported provider)
  • A terminal or command prompt
  • Basic command-line familiarity That’s it! Let’s get started.

Step 1: Create a New Vagrant Project

First, create a folder for your new virtual machine setup and initialize it with the Ubuntu box:

mkdir vagrant-ubuntu
cd vagrant-ubuntu
vagrant init ubuntu/jammy64
vi vagrant #this is to edit the file, 
Enter fullscreen mode Exit fullscreen mode

once you opened the file make sure to uncomment the private network line which contains the public address of the os and the public address line

This creates a file called Vagrantfile — the heart of your configuration

Step 2: Configure the Vagrantfile

Open the Vagrantfile with your favorite editor and tweak the settings.
You can adjust CPU, memory, and network configurations easily.

Example configuration:

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/jammy64"

  # Optional: forward host port 8080 to guest port 80
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Provider-specific settings
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2048"
    vb.cpus = 2
  end
Enter fullscreen mode Exit fullscreen mode

Step 3: Start the Virtual Machine

Once your configuration is ready, start the VM using:

vagrant up

This command downloads the Ubuntu box (if it’s your first time) and boots it up.
You’ll see messages as Vagrant connects to VirtualBox and starts provisioning the machine.

Step 4: Connect to Your Virtual Machine

Once it’s running, you can log into your Ubuntu VM:

vagrant ssh
Enter fullscreen mode Exit fullscreen mode

If everything went well, you’ll see the Ubuntu welcome message, along with system stats and login info.

Step 5: Run Basic Commands Inside the VM

Now that you’re inside, you can explore and test basic commands:

whoami           # should print 'vagrant'
mkdir testfile
touch textfile.txt
ls
rm textfile.txt
rmdir testfile
Enter fullscreen mode Exit fullscreen mode

You can also install packages, configure software, or run a web app — it’s your sandboxed Linux environment!

Step 6: Stop and Destroy the VM

When you’re done experimenting, you can safely shut down or completely remove the VM:

vagrant halt       # stops the virtual machine
vagrant destroy    # permanently deletes the VM
Enter fullscreen mode Exit fullscreen mode

This frees up your system resources and ensures a clean slate for next time.

This workflow is especially powerful for testing backend apps, DevOps scripts, or server configurations safely. Once you’re comfortable, try automating it with provisioning tools like Ansible or deploying pre-configured images.

Top comments (0)