To provide a simple (while not the only) way for Windows & Mac users to launch a virtual machine ("VM") with a Linux Desktop environment – sandboxed on their local computer.
Contributing
Contributions are more than welcome:
If you are new to the wonderful world of git (version control) – and/or are uncomfortable with the command line – download GitHub for Windows or GitHub for Mac.
Create a branch (git checkout -b my_feature_branch).
Commit your changes (git commit -am "Added a sweet feature").
Push to the branch (git push origin my_feature_branch).
Create a Pull Request from your branch into the master branch of this repo (please be sure to provide enough detail, so I can decipher your proposed changes). SeeCollaborating | GitHub Help.
Introduction
For many years, there were barriers surrounding the many unsatisfied Microsoft Windows users yearning for more and some Mac OS X users that developed an itch for tinkering with open-source tools. Namely, they did not have:
the cash-flow or desire to pick up a dedicated Linux box; or
the technical expertise to create a dual-boot environment – that is, a partition on their local hard drive from which to boot a Linux environment, side-by-side with Windows.
Besides, dual-boot environments carry the inconvenience of having to reboot your computer every time you want to work with the other OS (so much for multitasking!).
Well, ladies 'n gentlemen ... drum roll, please ...
Meet VirtualBox
VirtualBox is a cross-platform, open-source "virtualization product for enterprise as well as home use." VirtualBox is installed on an existing host operating system ("OS") – such as Windows or Mac OS X – as an application, i.e. a VM. While running as an application/VM on your computer, VirtualBox then allows a guest OS to be loaded and run, within its own virtual environment. Thus, VirtualBox can be used to run a virtual Linux computer inside your Mac or Windows PC, as opposed to next to it (such as in a dual-boot configuration).
To deploy a VM on one's computer, the user must first create a VM within VirtualBox and properly configure the slew of possible options. While this is really not as difficult as it sounds, the prospect can seem daunting to non-computer-geeks. Such unfortunates are in luck, however.
Meet Vagrant
Vagrant is also a cross-platform, open-source tool. After you install VirtualBox on your computer, Vagrant itself makes it so you do not need to deal with VirtualBox directly. Vagrant was created for software developers, so they could build and share computing environments with other developers. It works with virtualization software such as VirtualBox to provide a virtual machine (on your local Mac or Windows PC) that is sandboxed, or sectioned-off, from your local environment.
A Match Made in Heaven
Many users run a guest OS inside of VirtualBox without Vagrant. However,
Vagrant saves you the trouble of having to build a guest OS from scratch;
By simply downloading a pre-packaged virtual machine running a particular guest OS, named a vagrant box;
While supporting customization via the Vagrantfile. The primary function of the Vagrantfile is to describe the type of VM required for a project and how to configure and provision the machine.
Other possible VirtualBox configurations (although, outside the scope of this project) are:
Run a Windows 7, or Windows XP, VM on a Windows 8 machine;
Run Max OS X on Windows;
Run Windows programs and, consequently, the Windows OS, on a Mac;
And more!
How to Deploy
Start with any operating system ("OS").
Install the most recent release of VirtualBox, for your OS.
Install the most recent release of Vagrant, for your OS.
vagrant will now be available as a command in your terminal or Windows Command Prompt.
Microsoft Windows users: Can open a command prompt by pressing (on the keyboard) the Windows key followed by the R key, which will open the Run dialog box, and typing:
cmd
and pressing Enter.
Note: If Vagrant is already installed, use vagrant -v to check the version. You may want to consider upgrading if a much older version is in use.
Clone or extract the project's repository into a local directory, e.g.
OR download and extract the repository master zip file
Change into the new directory with cd vagrant-desktop
The First vagrant up
Start the Vagrant environment by executing the command: vagrant up
Be patient as the magic happens. This could take a while on the first run as your local machine downloads the required files & updates.
What Did That Do?
The first time you run vagrant up, a packaged box from the Ubuntu Cloud Images repository, containing a basic virtual machine, is downloaded to your local computer and cached for future use. The default Vagrantfile used by Vagrant's Linux Desktop Environment for Windows & Mac contains an installation of Ubuntu 12.04 LTS 32-bit.
After this box is downloaded, it begins to boot as a sandboxed virtual machine using VirtualBox. Once booted, it runs the included provisioning script, to install the Ubuntu desktop environment.
Note: Ubuntu's default desktop environment ("DE") is Unity. Feel free to modify the provisioning script (bootstrap.sh), if you would prefer a different DE, such as GNOME.
The time for all of this to happen depends a lot on the speed of your Internet connection. If you are on a fast cable connection, it will likely only take several minutes.
On future runs of vagrant up, the packaged box will be cached on your local machine and Vagrant will again apply the provisioning script, only if specifically requested.
Preferred: If the virtual machine has been powered off with vagrant halt, vagrant up will quickly power on the machine without provisioning.
Rare: If you would like to reapply the provisioning script with vagrant up --provision or vagrant provision, some time will be taken to check for updates and packages that have not been installed.
Very Rare: If the virtual machine has been destroyed with vagrant destroy, it will need to download the full package data on the next vagrant up.
How to Use
Now that you're up and running, start poking around and modifying things.
Your Windows or Mac desktop should now be substituted by a full-screen Linux desktop environment. Log in with the username vagrant and password vagrant.
You can also access the VM via the command line with the vagrant ssh command from your local Vagrant-LinuxDesktop directory. You can do almost anything you would do with a standard Ubuntu installation.
MS Windows users: An SSH client is generally not distributed with Windows PCs, by default. However, a terminal emulator such as PuTTY will provide access immediately. For detailed instructions on connecting with PuTTY, consult the Vagrant-LinuxDesktop wiki.
Power off the VM with vagrant halt and turn it back on with vagrant up.
Suspend the VM's state in memory with vagrant suspend and bring it right back with vagrant resume.
Reapply provisioning to a running VM with vagrant provision.
Destroy the VM and start from scratch with vagrant destroy.
Vagrant box
One concept to be mindful of is Vagrant's use of boxes. Vagrant uses .box files as templates from which to spin up a new VM. Instead of building a VM from scratch – which would be a slow and tedious process because you would first have to create a VM in VirtualBox and configure the proper settings – Vagrant uses a base, combined image of both a properly-configured VirtualBox VM with a guest OS already installed, to quickly clone a VM.
Such an individual base image is referred to as a box. Feel free to swap-out the URL in the config.vm.box_url directive of this project's Vagrantfile – that provides the default Ubuntu box – with the URL of either of the official Vagrant boxes:
or with a box URL from either of the following repositories hosting VM, or guest OS, images:
Ubuntu Cloud Images (pre-installed disk images that have been customized by Ubuntu engineering to run in the Vagrant local-virtualizaition environment).
Vagrantbox.es (a list of Vagrant boxes people have been nice enough to make publicly available).
Need Help?
Read the Vagrant Docs (while boring, that is a great place to get started).
Vagrant has a Mailing List for any topic related to Vagrant.
Open an Issue on GitHub if you run into trouble or have any suggestions.
The trailblazers at the uber-successful Varying Vagrant Vagrants, which – in addition to their great work on local WordPress development – have, in the process, created a roadmap for launching any local-development environment off the ground.
请发表评论