This post is dedicated to those like me who would like to be able to run Linux programs when we need to, but otherwise to shove it in a dark corner of our computers where we never need to see it again. I will introduce the basics of Linux and describe how to install it inside a virtual machine on Windows 7.
Linux comes in flavorsThe first thing to know about Linux is that it is “open source”, meaning that anyone and their mother can take the raw code, change it, and release their own version. There are a number of flavors, or “distributions”, of the software which various groups of people work on and support. One of the Ubuntu flavors would be best, simply because it is a fairly complete version with good updates and a fairly nice user interface. And Ubuntu is one of the simpler and cleaner ones.
What is a virtual machine, and why should I use it?A virtual machine is a essentially a piece of software that pretends to be a computer inside your computer, which allows you to install another operating system inside it. The benefit of this is that you can use Windows and the other operating system side-by-side simultaneously. There is some loss of performance, but it isn’t too bad.
Step 1. Download and install Oracle VM VirtualBox or Install Hyper-VThis is a free, highly recommended program that allows you to create and use virtual machines. Get it for Windows here. If you have Windows 8 Professional or later, however, you can install the Hyper-V components which makes for a much better experience. To do so, open the Start screen and start to type "Turn Windows features on or off". It'll be in the Settings section. Open that, check the box next to "Hyper-V" and click OK.
Step 2. Download the Ubuntu DVD Image.Now you’ll want to get the Ubuntu Linux operating system software. You can either get 32-bit or 64-bit versions. 32-bit should always be safe (as in error-free), so if you don’t know the difference, you can go ahead and get 32-bit.
Step 3. Create your Virtual Machine (VM)Run VirtualBox and click the “New” button. Give the VM a name and select Operating System “Linux” and Version “Ubuntu” or “Ubuntu (64-bit)”, depending on the version you decided to install. On the next page, allocate at least 1024 MB of memory. You can always adjust this later, but keep in mind that while the VM is running, that memory will not be available to your main computer.
On the next screen, leave the defaults for the virtual hard disk and move to the next screen. Since you are using Windows, using the VHD format would be best, as it can be opened by Windows and other virtual machines.
On the next screen, leave “Dynamically allocated” selected to allow it to use as little of your hard drive as it needs. On the next screen, change the maximum disk size to at least 40 GB. The OS itself only really needs 16, but you’ll want space for whatever you will be doing on it, especially if you plan to have local copies of protein and nucleotide sequence databases. Just keep in mind that it is possible to expand the maximum size after the fact, though it is a bit involved.
But that note aside, continue to the next screen, then click “Create” to create the virtual hard drive and “Create” again to finish!
For Hyper-V: Open the Hyper-V Manager and on the right under "Actions" select "New > Virtual Machine..." and follow the directions in the Wizard. Again I recommend 1024 MB of RAM, enable Dynamic Memory, create a dynamically-expanding hard disk as you would for VirtualBox, then select "Install an operating system from a boot CD/DVD-ROM", select "Image file (.iso):" and then find the Ubuntu DVD image you downloaded in Step 2.
Step 4: Configure the VMSelect the new VM and click “Settings” and then under “System” you may want to increase the number of processors to match the number in your machine (e.g. a dual-core CPU with hyperthreading has 4 virtual CPUs).
Under “Display”, increase the video memory to the maximum, but don’t enable 3D acceleration, as it just slows things down. If you want to work with a graphics-heavy program in Linux, you’ll want to install Linux as dual-boot. The Ubuntu website has a Windows Installer option for that.
Under “Audio”, this selection will depend on your system, but “Intel HD Audio” should be used with Windows 7 and Vista. The VM will tell you if there is an error, so you can change this setting.
For Hyper-V: To enable networking, in the Hyper-V Manager, under "Actions" on the right, choose "Virtual Switch Manager...". Create a new "Internal" virtual switch. Then select the VM and on the right under the VM's name, choose "Settings...". On the left select "Network Adapter" and choose the internal switch you just created. You can also adjust things as you would for VirtualBox, like the number of processors visible to it. Finally, open your computer's Network and Sharing Center, then on the left choose "Change adapter settings". For the adapter you use to connect to the internet (probably Ethernet or WiFi; note the "vEthernet" was created by Hyper-V), select it, right-click and select "Properties". Then go to the "Sharing" tab and check "Allow other network users to connect...". If prompted, select "vEthernet" as the home networking connection.
Step 5. Start the VM and install UbuntuNow click “Start” to run the VM. You may get an audio device error—take note if there is a problem later, but you should be able to safely ignore it. It won’t boot, of course—there’s no operating system installed! Go up to “Devices”>“CD/DVD devices”>”Choose a virtual CD/DVD disk file”, then find the DVD image you downloaded, which should be of the form “ubuntu-11.10-desktop-amd64.iso” (for 32-bit, “amd64” is replaced by “i386”). Then use “Machine”>”Reset”. The system should now boot from the DVD image. Take note of the informative pop-ups that tell you about how the VirtualBox program works.
For Hyper-V: You already told it to use the installation DVD image, so just select the VM in the Virtual Machine Manager and double-click it to open the 'monitor' and click the Start icon.
Once Ubuntu has loaded, follow the prompts to install it on the virtual machine.
Installation notes: You will probably want to check “Download updates while installing” and “Install this third-party software”. And note that is it safe to choose the default “Erase disk” because you are operating on a virtual hard disk, not your real hard disk.
It’s installed… what do I do now?First, install any updates available. An icon will soon appear to prompt your attention, and restart if it asks you to.
Then go up to “Devices”>”Install Guest Additions…” which loads a virtual DVD to install some helper drivers that improve the interaction between the VM (the “guest”) and VirtualBox.
Restart the VM by selecting the power icon in the upper right, selecting “Shut Down…” and then pressing “Restart”.
For Hyper-V: The newest versions of Ubuntu do not need any additional tools installed.
Now you might want to adjust the system settings (cog and wrench icon) to your liking.
One important thing will be to move files between your host system and the VM. You can set this up by going to “Devices”>”Shared Folders” and then clicking the “Add Folder” icon. Under “Folder Path”, click “Other…” to find the folder you would like to act as a thumb drive of sorts. you will probably want to make it permanent and auto-mount it.
For Hyper-V: There is a better way to access files on your host computer, which can also be used with VirtualBox: Set up a DropBox folder that syncs between them.
The Terminal: Welcome to 1985Now time to get familiar with the Terminal—since so much of Linux requires it, unfortunately. To open Terminal, click the top left toolbar button or press the Windows key and type “Terminal”. Once it is open, you’ll probably want to keep easy access to it, so right-click its icon and check “Keep in launcher” (the bar on the left is the launcher).
The terminal is essentially a text-only interface to the computer. You type commands to instruct the computer to do something. It is also location-dependent, and the prompt indicates the location it currently is—it starts at “~” which is the Home folder.
Note that the below is only necessary to use VirtualBox's shared folder.
Start by typing “sudo usermod –aG vboxsf <username>”, where <username> is your login for the VM. “sudo” tells the computer to run the following command as an administrator after authenticating you. “usermod” tells the computer to append (a) your account to the group (G) “vboxsf”, because members of this group have access to the shared folders. Press Enter, input your password to authenticate, and press Enter again to complete the command. Restart the computer as before.
Now you’ll probably want to create a shortcut to your shared folder. Of course, you’d think you could simply drag a folder somewhere or create a shortcut some other obvious way, but nope—back to the good-old terminal! Open the Terminal and type “ln –s /media/sf_<foldername> ~/Desktop”. This command makes a symbolic link (a shortcut) in the “Desktop” folder in your Home directory to the shared folder named “sf_<foldername>”, where <foldername> is what you called your folder in Windows, though with spaces replaced with underlines. Press Enter, and the shortcut appears!
Now you can easily move files back and forth.
By the way, typing “man <command>” in the terminal can get you some documentation on the command.
Some problems you might encounterMany Linux programs are just a bunch of files compacted together in a “package.” Because there’s apparently no good place to put such things, you generally put them in their own folder inside the Home folder, which can also appear as your username.
If you are lucky, the package will have a “Readme” file which has installation instructions for all the other things you need to install to get it to work. Some of these are fairly easy to get, by typing the command “sudo apt-get install <packagename>” in the Terminal. This tells the computer to run the command “apt-get” which looks for the package called <packagename> and install it.
Many times, Linux programs which come in a “.tar.gz” have to be compiled into the actual program from source code. To do this you first have to go into the terminal and navigate to the folder’s location. You can use the command “ls” to list the contents of a folder, and “cd <path>” to move to the designated subfolder. You can move multiple folder steps at once by separating them by a “/” symbol. You can move backwards by using “..” as the folder name. For example, “cd Folder1/Folder1-1” will move you to Folder1-1, which is inside Folder 1, which is inside your starting location. If you follow that by “cd ../Folder1-2”, you will step you back out into Folder1 and then forward into Folder1-2.
Now that you are in the program’s folder, you generally need to run the “make” command, which reads an instruction file and makes the program. To do this, however, you also need what is called a “compiler” which of course you don’t have. Luckily, if you try running “make” without having it, it will tell you that the command is not found. You take this command (often “gcc” or “g++”) and use the “sudo apt-get install <command>” to get it.
One problem you might run into is that a program which depends on another one doesn’t have the exact version available that you need, in which case you might actually have to modify source code to get them working. Hopefully you will not need to do this.
Another problem you might run into is that you think you are telling a program to run from Terminal, but Linux keeps telling you it isn’t there. That’s because it doesn’t actually look in the current directory, but looks at places specified in the system environment variables. To run such a piece of code by typing the name of the file, prepend “./” to it. This tells it to look in the current directory. I have no clue why it doesn’t try to look there in the first place.
Okay, I’ve ragged a lot on Linux here, and somewhat deservedly so. But if you do know how to use it, or parts of it, it can be very malleable and useful, emphasis on IF you know how to use it.
Good luck with Linux! You’ll need it.