How to set vagrant command globally

May 24, 2021 MrAnyx 1 min to read

This article will show you how to access vagrant commands globally on windows or linux. We will assume that vagrant and homestead are correctly installed.

  1. First of all, you will need to find or create a .bashrc file on your user directory. On windows, this file should be located in C:\Users\<your-user>. On linux it should by in /home/username
  2. Then, type in the following function :
function homestead() {
    ( cd homestead_directory_path && vagrant $* )

The function above will simply reach the homestead directory and then run the vagrant command you want.

  1. Then save the file.

⚠️ If your homestead directory location is : C:\data\homestead then, is this homestead_directory_path you should type /c/data/homestead

  1. Finally, restart your terminal and you're ready to go 👍.

Now, you can access each vagrant commands like vagrant up or vagrant ssh by typing homestead up or homestead ssh.

Cover by Mohammad Rahmani

This work is made available under the terms of the license Licence Creative Commons