Skip to content

How to run commands when starting up a Vagrant box

Some of us at Culture Foundry run vagrant instances for development. This virtual machine lets you manage different environments or work in a unix environment if that is your wish. It’s heavier weight than a solution like docker, but depending on your infrastructure and/or sysadmin skills, may be more intuitive.

Our development depends on a database, which may be PostgreSQL or MySQL. However, for the version of Ubuntu that we were running, MySQL didn’t start up, at least the version we were using. After some searching, the easiest solution to implement was just to put the startup script in the Vagrant file. This looks like:

config.vm.provision "shell", inline: "sudo service mysql start", run: "always"

You can use this syntax to run any command you want run once and only once as your Vagrant machine boots up. More on the shell provisioner here.

Take the first step to

reclaim the power of tech

Your goals, our guides.
Let's set great things in motion.

Work With Us

THE LIFT

Subscribe to THE LIFT

THE LIFT is our monthly e-newsletter full of tools, tips, resources, and real-world examples of how you can reclaim the power of tech, and a great way to keep us your radar.

Get THE LIFT