In Part 2 of this tutorial, I discuss how to setup your Windows 10 machine for the Ubuntu Rails VM.
1. Prepare Your Windows Machine
I used a desktop PC with Windows 10 Home. While most Windows 10 machines will work, a a Windows PC powerful enough to host a virtual machine is needed. How powerful depends on how much you load up your vm, or how many virtual machines you want to run at one time.
The software versions I used are below. You, of course, can install the latest versions of each, but your experience may then be a little different than what I describe here.
1.1 Install and Configure
Windows Software Needed
- Install Git BASH by installing Git for Windows (ver 2.22.0.windows.1)
- Install Vagrant for Windows (2.2.7) with Oracle’s Virtual Box
- Install Visual Studio Code (1.40.0)
You’ll want to run Git Bash and Visual Studio Code as an administrator. I created desktop shortcuts for each, then configured each shortcut to be run as an administrator.
Terminal Windows
Both Git Bash and VS Code provide terminal windows. I used Git Bash to setup some things before moving to Visual Studio Code’s terminal window. It’s up to you which terminal window to use.
Windows Directory Structure and Git Bash
1. Create a development directory and a working directory within it. My working directory:
/f/dev/work
2. Configure your Git Bash Windows desktop shortcut to start in the working directory and to run as an administrator (under the “Advanced” button in the picture).
3. Optionally, configure your bash prompt. Mine is set to the following:
PS1="\[\033[0;34m\]\u@\h: \[\033[0;32m\]\w\[\033[0;31m\]$(__git_ps1 " (%s)") \[$(tput sgr0)$\]\[\033[0m\] "
More Structure
Now, I’m a paranoid developer, believing that somehow I’m going to wipe files I don’t want to wipe, even with git repositories.
So, the files needed for the virtual machine live in a GitHub repository, and are cloned from GitHub to a development path. This is where I tweak the files for the VM, where the VS Code workspace file lives, and where I perform my git adds, commits, etc.
Development path
/f/dev/work/vmfiles/vmrails
Deployment path
/f/dev/work/vm/ror
When running changes I’ve made in the development of my vagrant files and virtual machine, I deploy from the development path to a folder off the deployment path where the virtual machine is launched by using a small deployment script. This should make sense as we go along.
2. Preparing Your Virtual Box
2.1 Clone GitHub Repository
So, next, we need the Vagrant files necessary for the virtual machine, so we need clone the files from my GitHub repository. So, from your terminal window under Windows, move to the development directory and clone my github repository:
$ cd /f/dev/work/vmfiles
$ git clone https://github.com/crjcodes/crj-vmrails
For more information about this repository, see the accompanying “Readme.md“.
Keep It Simple
I recommend the first time through this tutorial you keep it simple and leave the files alone. This means you will need to have a path to where you want to launch the vm, separate from your developmental work area, and you will need to tell the deployment script that path.
2.2 Updates
Optionally, update the vagrant box and plugins by running the Bash shell script, “update.sh,” included in the project,
$ cd /f/dev/vmfiles/vmrails
$ ./update.sh
or you can just run the updates you want directly, such as what’s in the “update.sh” as of the time this post was written,
vagrant box update
vagrant plugin update
2.3 Deploy to Launch Area
The deploy script will copy the necessary files from the development area to the deployment area, as we discussed in the section on structure, above. Use your working development directory and deployment directory in place of the parameters below.
$ cd {your project development directory}
$ ./deploy.sh [{deploy path} [{name of virtual machine}]]
If you do not enter a virtual machine name, “ror” will be used. For more details on “deploy.sh,” view it in your cloned repository’s root.
3. Before Launching Your Virtual Box
In brief, the Vagrant file will configure the virtual machine and prepare Ansible for the virtual machine. Ansible is what worked for me, but examples of other deployment tools you can use with Vagrant are out there.
3.1 Shifting Sands Again
When using a virtual machine, consider it a machine of moving parts. Software versions can change from run to run and influence what warnings and errors show up on screen once you launch.
Keep in mind:
- Updating Vagrant is manual and up to your discretion when you install a newer version
- The Virtual Box provider used is based on Vagrant default provider settings; I don’t change it
- Vagrant will use the box set in the Vagrantfile, auto-downloading and adding it as needed
- Vagrant Cloud will update this box from time to time. This, in turn, may change the version of the operating system and/or the versions of what is included with operating system
Controlling Versions Beyond Tutorial Scope
What and how of fixing software versions or auto-updating versions is beyond the scope of this tutorial
Next
After this Ubuntu Rails VM setup, in part 3 of this series, we will prepare the files for the virtual machine and deploy them.
Pingback: Ubuntu Rails VM Tutorial: Launch - Code Onward
Pingback: Ubuntu Rails VM Tutorial Introduction - Code Onward