in Web Development

Vagrant Up Bash Alias

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

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email