Logo

dev-resources.site

for different kinds of informations.

Vagrant Setup for macOS with Apple Chips

Published at
9/1/2024
Categories
vagrant
linux
macos
Author
flpcastro
Categories
3 categories in total
vagrant
open
linux
open
macos
open
Author
9 person written this
flpcastro
open
Vagrant Setup for macOS with Apple Chips

Hey guys!

In this short post, we will set up a simple environment to create VMs on macOS with Apple chips (M1/M2/M3 or newer) using Vagrant.

1. Introduction

What is Vagrant?

Vagrant is a tool that allows us to create and manage virtual machines easily and effectively. With it, we can create VMs from a configuration file called Vagrantfile, enabling us to share machine configurations easier, maintaining the consistency in our environments. This software has its main virtualization providers under the hood, such as VirtualBox, VMware, QEMU, Parallels, Docker, Hyper-V and others.

Main Features

  • Consistent and reproducible environments: Through the Vagrantfile configuration file, we can use the same environment for all developers involved in a project, for example.

  • Reduced manual work and errors: Since the environment configurations are done through code, the manual work required to create multiple VMs is drastically reduced, it also minimize the margin for error.


2. Preparing the environment

Requirements

  • OS: macOS 11.0 (Big Sur), but it is recommended to use the most recent version of macOS (such as Monterey 12.0 or Ventura 13.0) for better compatibility and performance.

  • Processor: Apple M1/M2/M3 or newer...

  • Package Manager: Homebrew

Installation

First, let's install Homebrew, if you don't have it yet.

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Now, let's install QEMU, an open-source virtual machine emulator and virtualizer. You may choose another one if you prefer, like VMware, VirtualBox...

# Install QEMU
brew install qemu
Enter fullscreen mode Exit fullscreen mode

Lastly, let's download Vagrant itself and the plugin for QEMU.

# Install Vagrant
brew tap hashicorp/tap
brew install hashicorp/tap/hashicorp-vagrant

# Install Vagrant plugin for QEMU
vagrant plugin install vagrant-qemu
Enter fullscreen mode Exit fullscreen mode

3. VM Configuration (arm64)

Create a folder to store the Vagrant configuration file.

# Create a directory
mkdir linux-machine && cd linux-machine
Enter fullscreen mode Exit fullscreen mode

Inside the created directory, build the machine configuration file.

# Generate a Vagrantfile
touch Vagrantfile
Enter fullscreen mode Exit fullscreen mode

Using a text editor of choice (nano, vim, VSCode...), add the following code:

Vagrant.configure("2") do |config|
  config.vm.box = "perk/ubuntu-2204-arm64"
  config.vm.provider "qemu" do |qemu|
    # set the port of your preference
    qemu.ssh_port = "9999" 
  end
end
Enter fullscreen mode Exit fullscreen mode

NOTE: The image used was perk/ubuntu-2204-arm64. But you can use any other that is compatible with the QEMU provider and the arm64 architecture. You can find more images on Vagrant Cloud. For example, the image generic/debian12 also offers compatibility with QEMU and arm64.


4. Launch

Download the image and launch the VM.

# Download the image and launch
# This may take a while
vagrant up --provider=qemu
Enter fullscreen mode Exit fullscreen mode

Access the machine’s command line via SSH.

# Log into the VM
vagrant ssh
Enter fullscreen mode Exit fullscreen mode

Well done, your new environment is all set up. :)

Here are some Vagrant commands to help you out:

bash
# See the machine status
vagrant status

# See downloaded images (box)
vagrant box list

# Remove images (box)
vagrant box remove box-name
Enter fullscreen mode Exit fullscreen mode
vagrant Article's
30 articles in total
Favicon
Comandos Básicos de Vagrant
Favicon
🔋⚡ Ensuring High Availability with Two-Server Setup Using Keepalived
Favicon
Using Vagrant to Provision a VM and Multiple VMs
Favicon
How to Create and Configure a Multi-VM Vagrant Setup for Web and Database Servers
Favicon
Error : Loading Vagrant Up
Favicon
[pt-BR] Como utilizei o Vagrant e o Virtual Box para desenvolvimento local
Favicon
Deploying a Spring Boot Banking Application with Docker
Favicon
Resizing the disk on a Vagrant virtual machine
Favicon
🚀 Creating a Kubernetes Cluster with Vagrant: A Step-by-Step Guide 🚀
Favicon
Setup a Docker Swarm cluster using Vagrant
Favicon
Solve "[email protected]: Permission denied (publickey)" error
Favicon
Vagrant ssh alternative
Favicon
Vagrant Setup for macOS with Apple Chips
Favicon
EXPLORING DOCKER CONTAINER USING VAGRANT
Favicon
Automate Your local VM workflow
Favicon
Day 3: Exploring Vagrant and Linux Server Setup
Favicon
Vagrant: A Comprehensive Guide to Managing Virtual Environments
Favicon
Vagrant and VMWare Fusion in Mac M1
Favicon
Windows GitHub Self Hosted Runner inside a Linux Container
Favicon
How to Enable a Virtual Machine on Your Windows Laptop With Vagrant and Git Bash
Favicon
Vagrant CLI Commands Cheat Sheet
Favicon
Install Virtual Machine With Vagrant & Remotely Access it
Favicon
Run Vagrant VMs in a M1/M2/M3 Apple Sillicon Chip
Favicon
Exploring Vagrant: Simplifying Development Environments
Favicon
Do M1 Mac Dream of x86 Linux?
Favicon
Vagrant - configurando VM's de forma performática
Favicon
Getting Started with Vagrant for Local Development Environments
Favicon
Vagrant For Beginners: Box Basics in Vagrant.
Favicon
Vagrant For Beginners: Creating Your First Virtual Environment.
Favicon
Getting started with Vagrant: a beginner's Guide

Featured ones: