Vagrant provides the framework and configuration format to create and manage complete portable development environments. These development environments can live on your computer or in the cloud, and are portable between Windows, Mac OS X, and Linux. Sep 22, 2020 Virtual Box can be installed on Windows, Mac-OS, Linux, Solaris, and Open Solaris. Virtual Box + Vagrant = ? Vagrant and Virtual Box can stimulate the production environment of your app.
Caution! Hello there, intrepid explorer! This post is old. The content might be out of date, and our opinions might have changed.
Making websites is a funny old game. The ubiquity of having a browser on your phone or your fridge is the web's killer feature. It is also a developer's nightmare. With several major browsers to deal with, and some not even available on my computer, why do I even bother?
Internet Explorer (IE) has, for one reason or another been the bane of developers lives for a long while, and hasn't been available on OSX since 2003. At Bluegg, like a lot of studios we only use Macs. And (like a lot of studios), we have a Windows PC locked in a cupboard which we can log into to test sites on Microsoft browsers.
Thankfully, Microsoft has gotten its sh!t together in recent years. IE11 (and now Edge) are pretty good, and definitely not bottom of the class any longer.
As well as making a decent stab at browsing, they've also gone all developer friendly. Over the last couple of years, they've released a bunch of (free) Windows virtual machines on all platforms. Everything from IE6 on XP, all the way up to Edge on Windows 10.
As well as making these for a few virtual machine (VM) providers, they also provide Vagrant environments. Vagrant is a Command Line tool to enable sharing, installing and running of development environments. It makes the process of setting up a VM slick and easy.
If you want to follow along at home, go and start downloading the VMs from Microsoft (they take ages). I recommend setting fire to your computer and yourself before you develop anything for IE6 or 7, so I got IE9 on Windows 7, IE10 on Windows 8, IE11 on Windows 8.1 and Edge on Windows 10. I feel like that gives me a good spectrum of operating systems and browsers.
In the meantime, install VirtualBox. This is the software for running virtual machines—we won't have to touch this too much once its installed. Go to the downloads page and grab the version for OS X Hosts (the UI is pretty awful, but you need to click the AMD64 link).
Next, we need to install Vagrant. Go to the downloads page and get installer for your system. I'm gonna get a quick game of darts in while you set that up..
Done? Good-oh. Let's get setup.
First, set up some directories for your VMs. Then extract the VM files into them. Here's one I prepared earlier:
I mentioned earlier that vagrant is a command line tool. We're gonna get in the Terminal now—we only need to use 3 commands though:
vagrant init
, vagrant up
and vagrant halt
. Don't fear the Terminal.Open the Terminal app and direct yourself to one of those directories (hint: You can drag the folder (eg: IE9) from Finder into Terminal to do this). If you've used my directory structure above you can write the following and press enter:
(the / characters need to go in front of any spaces or Terminal will think you're crazy)
This will create a Vagrantfile in the folder. A Vagrantfile has all the settings for your Vagrant environment. Open that file in your text editor of choice. Find the lines (The hashes are comments by the way):
Replace it with this, and save the Vagrantfile:
For the curious, here's what we did:
- We uncomment the first line and last line—this starts the config for our VM provider, VirtualBox and ends the config block.
- We uncomment the third line—which ensures we can actually see Windows when it boots up. Vagrant runs the environment without a user interface by default, so we need to turn it on.
- Finally we add a line which will configure the amount of memory allocated for video. The minimum to allow the screen to be used at fullscreen (and basically anything over 1000px wide) is 48MB.
Back in Terminal, type the following command and enter:
Wps office online, free full. That will kick off the Vagrant environment. It will go and download everything it needs so it might take a mo. Once its up you should see VirtualBox open and a windows will boot up in a window.
Note: There will be an error in the Terminal—this is to do with SSH not being available in the Windows VM. Don't worry about it as you won't need to SSH into the box for IE testing.
When the machine has started you should see Windows boot and log you in. You can now open IE or Edge and start browsing. You will probably want to access your localhost (as in your Mac host computer's localhost), you'll need to browse to http://10.0.2.2 (and possibly include your port number).
To stop the VM, pop back into Terminal and enter
vagrant halt
. That will gracefully shut everything down ready for the next time you need it. You can also control the VM via the VirtualBox UI—but that's gross.Have fun browsing on the Edge.. I hope you'll explore Vagrant and VMs a little more.. It's virtually painless.. Ok I'll stop. Bye.
![Mac virtualbox vagrant code Mac virtualbox vagrant code](/uploads/1/1/9/5/119511037/906322076.png)
More posts
Learn about virtual machines and how you can use Vagrant and VirtualBox to set up a local Ubuntu installation.
I've gotten to the point in my web development career where I can no longer avoid the words VirtualBox, Vagrant, and Docker. Thanks to my friend Timm Stelzer, I finally got over my fear of the unknown and delved into the world of virtual machines via Vagrant and VirtualBox.
Now that I've finally used them, I can see how fun and useful they are, and since I've just set everything up myself in 2017 with the most up-to-date installations I could find, I can share what I've learned with you.
Prerequisites
The only prerequisite to this article is command line knowledge, and it is mandatory. This article that I wrote, How to Use the Command Line, will tell you everything you need to know, from moving around directories, creating files, and
ssh
ing into servers. If you're not familiar with any of that, please read the aforementioned article.Goals
In this tutorial, we will learn:
- What VirtualBox is
- What Vagrant is
- How to use Vagrant and VirtualBox in tandem to set up a local Ubuntu installation
- How to connect to the Ubuntu server we create
Introduction
VirtualBox is basically inception for your computer. You can use VirtualBox to run entire sandboxed operating systems within your own computer.
Vagrant is software that is used to manage a development environment. Through the command line, you can grab any available OS, install it, configure it, run it, work inside of it, shut it down, and more.
Using VirtualBox and Vagrant, you can simulate the production environment of your app or website. For example, if you're using Digital Ocean or AWS to run a Virtual Private Server (VPS) in the cloud running Ubuntu, PHP, and MySQL, you can install your local version to have all the same versions of that software, while keeping your own computer's software untouched. This can reduce and eliminate bugs and errors that result from trying to develop code for a production server on an environment that does not match.
In this tutorial, we're going to install Vagrant and VirtualBox, and install Ubuntu Server. We're going to connect to the Ubuntu server though
ssh
to confirm that everything is running properly.After this tutorial, learn to install a LAMP server on the environment we create.
Step 1 - Install Virtual Box and Vagrant
Install VirtualBox
Go to the VirtualBox download page, choose your operating system (Windows or macOS) and download and install the software.
I clicked OS X and the download started.
Install Vagrant
Go to the Vagrant download page, choose your operating system (Windows or macOS) and download and install the software.
Again, I chose Mac OS X.
Step 2 - Install Ubuntu Server with Vagrant
Create a directory for your virtual host to live. I created a VirtualMachines directory (which will potentially contain all of my virtual machine installations), and made a new directory within called ubuntu for this specific installation to live. The whole path is as follows:
Your path will be slightly different for Windows, using
C:/
, but otherwise will be the same idea.Install Ubuntu Box
Mac Virtualbox Vagrant Life
You can Discover Vagrant Boxes via the Vagrant Cloud.
ubuntu/trusty64
is the most popular box (machine), with nearly 30 million installs and updated within the last day. This is the one we'll be using.In Terminal (Mac) or Git Bash (or whatever shell you're using on Windows), type the following to install Ubuntu Server 14.04.
After a few moments, this will be the output to let you know it's successful.
Now initialize the new
vagrant
in your VirtualMachines/ubuntu directory with the init
command.Finally, get Ubuntu up and running with the
vagrant up
command.When you see 'Machine booted and ready!', everything is good to go!
Fixing Guest Additions Error
This is great, and all set up. However, you may have gotten this error:
This might not be a problem, but let's make sure it doesn't become a problem. First, use the
halt
method to shut down your currently running Vagrant.Let's quickly install a plugin called
vbguest
to fix this error.It will run through some more commands, and most likely the above error will still persist. Let's reload the Vagrant machine with the
reload
command.Now the errors will be gone.
What about VirtualBox?
Looks like we didn't use VirtualBox for anything at all. But go ahead and open up the VirtualBox application. This is what you will see running:
As you can see, VirtualBox is letting us know that Ubuntu is running properly. We don't really need to know much more about it at this point.
Step 3 - SSH into Ubuntu
Now we have this Ubuntu operating system set up on our computer, but how do we access it? Just like you would access any remote Linux server through the command line, you will do the same with Vagrant. Run
vagrant ssh
to securely enter the Ubuntu virtual machine.When you login, you will see something along these lines.
You're in! You now have a complete Ubuntu Server installation running through VirtualBox on your computer, and you're connected to it. Type
exit
at any time to exit out of the server, and vagrant halt
to shut it down.Conclusion
Install Vagrant Mac
Here is a review of the commands we used with Vagrant today.
Command | Purpose |
---|---|
vagrant box add ORG/BUILD | Add a new virtual machine |
vagrant init ORG/BUILD | Initialize virtual machine |
vagrant up | Start up virtual machine |
vagrant reload | Restart virtual machine |
vagrant halt | Shut down virtual machine |
vagrant ssh | SSH into the virtual machine |
Note: All these commands must be done locally from the directory in which you want the virtual machine to be installed, except
vagrant box add
.As a review, VirtualBox is the software that runs the operating system, and vagrant will give you the methods to manage them. You can also think of vagrant as a package manager that has a repository of different operating systems to use.
Vagrant and VirtualBox can be used to create a local environment that matches the production environment of your server.
Mac Virtualbox Vagrant Code
Move on to Part 2: Setting up LAMP (Linux, Apache, MySQL, and PHP) from the Ubuntu Server environment we created, and how to access it from your local computer.