I’ll not go into every detail of why use Vagrant or Local Server. If you came to read this article, this means you already know what is it and why anyone should use it. If not, you can go ahead and find many articles explaining the use of Vagrant.
In very short Vagrant gives you the ability to create separated Virtual Machine inside your working machine. You can ssh and perform any action that you can on any server machine. You can install the different variant of Linux servers, use it and destroy anytime you want without any trace.
In this article, I’ll guide you to Up and Running Vagrant with Linux Ubuntu 16.04 distribution. I used macOS while writing this article but most of the step from this article should be same for any other operating system.
The following is the general procedure that I’ve adopted after learning the fundamentals and working through some experimentation. Follow these steps and you should be up and running without any issue.
Add Ubuntu Distribution
Configure IP Address
Run The VM
1. Install VirtualBox
Vagrant isn’t a stand-alone software which handles all the virtualization. To run itself it needs some help from VirtualBox behind the scene. To install VirtualBox, please head over to the download page and choose the latest stable version based on your operating system. The installation process should be same as installing other software on your operating system. For further help, you can read the manual on VirtualBox download page.
2. Install Vagrant
After you’ve successfully installed VirtualBox. Now you can go ahead and download Vagrant. If you’re running macOS you can easily install it using the DMG file that you downloaded from their website. Follow their instructions to install it on other OS.
3. Add Ubuntu Distribution
First, you should create a new directory for your VM. This is where your Vagrantfile will be stored. You should always create new folders for different VM.
Run the commands below to create a new project directory and initialize Ubuntu image on it.
vagrant init ubuntu/xenial64
4. Configure IP Address
Most likely you would want to install Apache, Ngnix or any kind of web server on your VM. Vagrant doesn’t provide any GUI where you can install browser and browse
localhost instead it gives you a private IP address to use it inside your local network. You can use that IP in your working machine browser to access your web servers etc. Let’s configure it.
new-vm/Vagrantfile file in any text editor and look for
private_network and uncomment the following line. You can change the IP address there if you want. But I’m keeping the default value
192.168.33.10 for simplicity. Save and close.
5. Run The VM
Now that we have initialized everything to run Linux inside our VM, we are ready the run the VM.
Now our VM is up and running in the background. You can ping the IP address to confirm.
That’s it!! Now you can ssh and run any Ubuntu command inside your VM.
sudo apt-get update
Close SSH Connection
While you’re inside the Ubuntu VM, Run the command to disconnect SSH connection.
Turn OF Your VM
Destroy Your VM
Navigate to your project folder. For me it’s
new-vm and now run the following command.
These are the fundamentals to use Vagrant. You can perform pretty much any task that you can inside any other Virtual Server.
Thanks for reading.