Vagrant Up Bash Alias

in Web Development

Here is a quick tip to improve your workflow as a developer working with Vagrant.

During my day-to-day job I use Vagrant with Homestead all the time, it allows me to quickly create a virtual environment perfect for use in Laravel.

Because I use Homestead on a per project basis at the start of everyday I always open terminal (cmd+t), navigate to the project directory (cd project-directory), then start vagrant (vagrant up), then ssh into the vagrant box (vagrant ssh).

As I do the same thing everyday you can improve this process by using a bash alias to speed up the process.

All you have to do is add the following to your .bash_profile file. If you're on a mac you just need to create a new file in your user directory nano ~/.bash_profile and add the following.

# Vagrant
alias vup="vagrant up && vagrant ssh"
alias vh="vagrant halt"

# Projects
alias start:project="cd PROJECT_DIRECTORY && vagrant up && vagrant ssh"

Now when you start a new terminal instance you'll have these alias available to you, just type vup and vagrant will try to start up in the current directory you're in.

One that I use every day is starting a new project just by using start:project-name which navigates to the project directory and start vagrant and then ssh into that new virtual machine.

Now I can get started with the project much quicker than I used to.

What things do you add to your .bash_profile file? @paulund

Subscribe To Newsletter

Get weekly updates to your email