Getting Started Testing with Linux virtual machine on Windows host
Boost developers using Windows as their development platform may occasionally wish to run local tests on Linux, too. A Linux virtual machine running on the developer's Windows host machine is an easy and free way to do just that. A Linux or Mac developer could do the reverse, although doing so would require a Windows license be purchased, but this article is limited to the Linux on Windows case because that's what I'm familiar with.
I use the Ubuntu Linux distribution because it is popular and works for me. I'm not a Linux expert, however, and other Linux distros would certainly work. Michael Cox reports he runs Fedora Linux in VirtualBox mainly because it tends to be one of the first distributions to release the latest g++/clang++ compilers.
Likewise, the article is limited to VirtualBox because that's the virtual machine manager I use. It is free, ease to install and use, and worked better for me than several similar packages. But that comparison was some years ago and your mileage may vary.
VirtualBox and Ubuntu both have excellent installation instructions, but if they are new to you it still takes a while to figure out the various choices. The hope in documenting my personal installation process is to get you started quickly.
Initial downloads and installation
- Download the Ubuntu Desktop installer, choosing the 64-bit flavor unless you have less than 2GB of RAM. The
.iso
file downloaded will be used later. - Download the VirtualBox installer for Windows hosts.
- Run the VirtualBox installer, selecting the default when offered a choice.
Create a new virtual machine
- Run VirtualBox. Click the New button to create a new virtual machine. My host machine has four cores with hyper-threading and 16GB of main memory, so I give the virtual machine 2GB of main memory. I also give it 20GB maximum of disk space - VirtualBox only allocates that much if actually needed.
- Once the virtual machine has been built, click Settings (gear icon) and set:
- System: Processor: 2 CPU's.
- General: Advanced: Shared clipboard: bidirectional
- General: Advanced: Drag'n'drop: bidirectional
If you want to change any of the features of the virtual machine at a later time, you can do so via Settings.
Install Ubuntu on the virtual machine
- Select the virtual machine, it it isn't already selected.
- Click Start. When asked to specify a startup disk, browse to your download folder and select the Ubuntu
.iso
file you downloaded earlier. It will have a name similar toubuntu-13.10-desktop-amd64.iso
, except the version number and machine architecture may differ. - If a message about mouse integration appears, you probably want to check "Do not show message again".
- When the desktop appears, select "Install Ubuntu".
- Check the box: Download updates while installing.
- Check the box: Install this third-party software.
- Hit "Continue", "Install now", and then other than entering your name and the computer name, just keep accepting the defaults. But you probably want to choose "Log in later" for Ubuntu One
At this point, the install starts to run. It does quite a bit of downloading files, and one or two times I have had hangs almost certainly related to network problems or overloaded servers. When that happened I verified the md5 checksum for the Ubuntu .iso
file, removed the virtual machine from VirtualBox and just started over. But usually everything goes smoothly.
Post installation restart and VirtualBox Additions install
The first thing to do after the install is to install the VirtualBox Additions. These are helpers such as device drivers that markedly smooth integration between the Windows and Ubuntu desktops.
- A Ubuntu restart is required after the install finishes. Sometimes the post-install shutdown requires hitting Return (aka Enter).
- After the post-install shutdown, start the virtual machine again.
- When the Ubuntu Desktop appears again, from the virtual machines menu-bar select "Devices" and then "Insert Guest Additions CD Image...".
- When asked if you would like to run the VBOXADDITIONS, click "Run". A terminal window (Linux-speak for command line window) will open and the additions will build. When you see the "Press Return to close this windows..." message, hit return.
- Some of the additions don't become effective until a reboot, so click the vaguely gear-like icon in the upper right corner of the Ubuntu Desktop, and select: Shut down...
Set up Ubuntu Terminal
- Start the virtual machine.
- Verify that if the Windows window that the virtual machine runs in is resized, the Ubuntu Desktop within it is automatically resized. That's a sign the VirtualBox Additions are installed properly.
- Click the vortex-like icon at the top of the launch bar on the left side of the Ubuntu Desktop window. Enter "terminal" (without quotes) in the search box that appears, and hit return. Drag and drop the Terminal icon that appears to the launch bar.
- Click the Terminal icon now on the launch bar. A terminal window (I.E. command line window) now appears running the
bash
shell.
Note: Your clipboard is being shared between Windows and the Ubuntu Linux virtual machine, so you can copy-and-paste or drag-and-drop stuff between windows on the two machines, just like you do between windows on Windows.
Install Git, GCC, and Clang
- In the terminal window, check for the presence of Git, GCC/g++, and Clang/clang++ and install if necessary. Portions of command responses are shown where helpful:
$ git The program 'git' is currently not installed. You can install it by typing: sudo apt-get install git $ sudo apt-get install git [sudo] password for beman: ... After this operation, 19.7 MB of additional disk space will be used. Do you want to continue [Y/n]? y ... $ g++ The program 'g++' can be found in the following packages: * g++ * pentium-builder Try: sudo apt-get install <selected package> $ sudo apt-get install g++ ... After this operation, 29.6 MB of additional disk space will be used. Do you want to continue [Y/n]? y ... $ clang++ The program 'clang++' is currently not installed. You can install it by typing: sudo apt-get install clang $ sudo apt-get install clang ... After this operation, 141 MB of additional disk space will be used. Do you want to continue [Y/n]? y ... $ git --version git version 1.8.3.2 $ g++ --version g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ clang++ --version Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2) Target: x86_64-pc-linux-gnu Thread model: posix
Set up ssl
We need to set up ssl before pushing anything to GitHub. All that has to be done is to copy your .ssh directory from your Windows user directory to your Linux home (aka ~) directory. VirtualBox enables sharing between Windows and Linux file systems, but that hasn't be configured yet so just on Windows copy the .ssh directory to a USB flash drive and then on Linux copy it to your home directory.
- Insert a USB flash drive, click "Open folder to view files" in the Windows notification dialog box that appears.
- In the Windows Explorer window, go to your home folder (usually c:\Users\Your-name), then drag-and-drop the
.ssh
folder to the
USB drive in Computer.
- In the virtual machine menu bar, click Devices, hover over USB Devices, select your USB memory drive from the drop-down list.
- In the Ubuntu launcher bar, hover over the filing-cabinet icon. Click on the Files window that appears to give it the focus, then hit ctrl+H on the keyboard or click the View options down-arrow-like icon and click Show Hidden Files.
- You should now see a .ssh folder. Drag-and-drop it to the Home icon on the left sidebar of the window.
Set up Git
$ git config --global user.name "Your Name" $ git config --global user.email you@what.ever $ git config --global core.autocrlf input $ git config -l user.name=Your Name user.email=you@what.ever core.autocrlf=input
Set up user-config.jam
$ gedit user-config.jam
That will fire up gedit
, a graphical text editor useful for editing text files including C++ program files.
Copy these two lines into the gedit
window, remembering that spaces are significant in jam files:
using gcc : : : <cxxflags>"-std=c++11" ; using clang : : : <cxxflags>"-std=c++11" ;
Hit Ctrl-S, then close the program by clicking the small x icon at the top of the gedit window.
Set up Boost
This is the procedure described in Getting Started with Modular Boost.
$ git clone --recursive git@github.com:boostorg/boost.git modular-boost Cloning into 'modular-boost'... ... cd modular-boost $ ./bootstrap.sh ... $ sudo mv b2 /usr/local/bin
That last command moves b2
to /usr/local/bin
, which is in the default path and so allows use of b2
without specifying the path. For example, this should now work:
b2 headers
Continue with regular maintenance operations
See Getting Started with Modular Boost Library Maintenance for details. You should be able to run the usual git operations and run tests with either the clang or gcc toolsets.
--Beman Dawes