Installing the Vitual Machine at Home

Last updated: June 5, 2020

Tool Recommended Version for CSE 3901
Virtual Box 6.x (tested 6.1)
Ubuntu/Lubuntu 20.04 LTS Desktop (64-bit)
Ruby 2.6.6
Rails 6.0.3

Overview

To set up our virtual machine:

  1. Download Virtual Box and Ubuntu
  2. Create a virtual machine running Ubuntu
  3. Customize the Ubuntu installation
  4. Install Ruby and Rails on the virtual machine
  5. Install RubyMine on the virtual machine (optional)

Questions?

See the troubleshooting guide for solutions to some common problems.

Step 1: Download Virtual Box and Ubuntu

Note: If you have an older home machine, try the Lubuntu distribution instead. The installation and configuration directions are virtually identical to Ubuntu. While Lubuntu is more responsive (especially on older hardware), its user interface is more primitive.

  1. Download the appropriate Virtual Box platform package binary for your host machine's operating system from virtualbox.org.

  2. Download Ubuntu Desktop (64-bit) ISO from ubuntu.com.

    1. Option 1 (slow): click "Download" and wait.
    2. Option 2 (faster): follow "Alternative downloads and torrents" and use a a BitTorrent client (e.g., http://www.bittorrent.com) to download the 20.04 Desktop (64-bit) torrent.

Step 2: Create a Virtual Machine Running Ubuntu

Note: Macs with M1 chips are not capable of emulating x86/64 architectures. To emulate Ubuntu on a Mac with an M1 chip, please use UTM. 1. Install Virtual Box on your home machine (accepting Oracle drivers if prompted). 1. Run Virtual Box. 1. Machine > New… then use the following values in the wizard:

**Name** | Something of your choosing (_e.g._, Ubuntu-20.04-64bit)
**Type** | Linux
**Version** | Ubuntu (64 bit)
**Memory size** | _at least_ 4 GB (recommend about 1/2 of your machine's installed RAM)
**Hard drive** | Create a virtual hard disk now
**Hard drive file type** | VDI
**Storage on physical hard drive** |  Dynamically allocated 
**File size** | 16 GB
  1. Install Ubuntu on the new virtual machine by first starting the newly created machine (Machine > Start > Normal Start), then selecting the Ubuntu ISO file downloaded in Step 1 as the start-up disk. As Ubuntu boots up for the first time, use the following responses:
    1. Select "Install Ubuntu" (not "try")
    2. Select "Normal in both "Download updates" and "Install third-party software"
    3. Select "Erase disk and install Ubuntu" (don't worry, it's the virtual machine's hard disk that will be erased!)
    4. Enter your name (e.g., Jane Doe), a computer name (e.g., helium) a username (e.g., jdoe), and password
    5. Restart (When prompted to "please remove installation media", just hit enter)
  2. Configure the virtual machine to make it easier to work with.
    1. Log in to the virtual machine, then use the top menu of the Virtual Box window to select Devices > Insert Guest Additions CD image. Click Run if the CD does not run automatically. You may be prompted for your password. Wait for installation to complete, then eject the CD (right-click on the CD in the task launcher along the left side of the desktop, Eject).
    2. In the same Virtual Box VM menu, click Devices > Shared Clipboard > Bidirectional. This selection allows you to cut-and-paste from the guest to host and vice versa.
  3. (optional, only for new host machines) Enable 3D acceleration. First shut down the virtual machine (click the power icon in upper right corner, then Shut Down…), then from the Virtual Box Manager window click Settings > Display > Enable 3d acceleration.
  4. (optional, only for multicores) If your VM is sluggish, you might get better perfomance by allocating more processors. First shut down the virtual machine, then from the Virtual Box Manager window click Settings > System > Processor > choose 2 or more.

Step 3: Customize the Ubuntu Installation

The account you created in the previous step has administrator privileges which will allow you to do the customizations described below.

A terminal window can be openned using the keyboard shortcut Ctrl + Alt + T.

Required Customizations

  1. Open a terminal and update the distribution by typing the following commands (the "$" is the command prompt, don't type that! While "#" indicates a comment):

     $ sudo apt update
     $ sudo apt upgrade
     $ sudo reboot
    
  2. Install some useful linux tools:

     $ sudo apt install git
    
  1. Install a full-featured editor. Ubuntu comes with several basic editors, including nano, vim, and gedit. You can use whatever editor you like, but I recommend choosing one of vim, emacs, or sublime. The first two (vim and emacs) are old-school-cool, free, open-source, lightweight, and universally available on all flavors of unix. Knowing one of vim or emacs allows you to log in to some remote server and edit files there, even through a terminal ssh session. However, it will take some time to learn how to use either of these editors well. Sublime, on the other hand, has very little learning curve. It can be used for free while evaluating it (for an unlimited time), but if you decide to adopt it you should buy a license ($70).

    Depending on which editor(s) you choose, do one (or more) of the following:

     # for emacs
     $ sudo apt install emacs
    
     # for sublime
     $ wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
     $ sudo apt install apt-transport-https
     $ echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
     $ sudo apt update
     $ sudo apt install sublime-text
    
  2. Create an SSH private-public key pair to facilitate logging in to a remote machine without typing a password:

     $ ssh-keygen -t rsa -b 4096
    

    When prompted, accept the default location (~/.ssh/id_rsa) and default passphrase (i.e., empty for none).

  1. Add the terminal to the launcher. With the terminal window open, right-click on terminal's launcher icon (i.e., along the left side of the screen) and select "Lock to Launcher".

Step 4: Install Ruby and Rails on the Virtual Machine

  1. Install rbenv as well as ruby-build (a useful rbenv plugin). Both steps are accomplished via the rbenv-installer script:

     $ wget -q https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer -O- | bash
     $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
     $ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
     $ exec $SHELL
    
  2. Install Ruby.

     # first install some Ruby dependencies
     $ sudo apt install zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev
     $ rbenv install 2.6.6 # this step takes several minutes
     $ rbenv global 2.6.6  # set default ruby version
     $ ruby -v # confirm it works
    
  3. Install Rails.

    1. Rails requires both a JavaScript runtime and the Yarn package manager. NVM is the node package manager which allows you to install and manage different NodeJS installations.

       $ sudo apt install curl
       $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
       $ Close and reopen the terminal (or run source ~/.bashrc)
       $ nvm install 12 --lts
       $ nvm alias default 12
       $ npm install yarn -g
       $ sudo npm install yarn -g #
      
    2. Install the Rails gem:

       $ gem install --no-document rails -v 6.0.3
      
  4. Confirm Rails installation with a system test.

     $ mkdir rails_work
     $ cd rails_work
     $ rails new demo
     $ cd demo
     $ rake about  # version info, checks for a javascript runtime, etc
     $ rails server
    

    The output of the last command should look something like:

     => Booting Puma
     => Rails 6.0.3.x application starting in development 
     => Run `rails server --help` for more startup options
     Puma starting in single mode...
     * Version 4.3.5 (ruby 2.6.6-pxx), codename: Mysterious Traveller
     * Min threads: 5, max threads: 5
     * Environment: development
     * Listening on tcp://127.0.0.1:3000
     * Listening on tcp://[::1]:3000
     Use Ctrl-C to stop
    

    You can kill the server with Ctrl-C (in the terminal window in which it is running):

     ^C- Gracefully stopping, waiting for requests to finish
     === puma shutdown: yyyy-mm-dd hh:mm:ss -0400 ===
     - Goodbye!
     Exiting
    

Step 5: Install an IDE on the Virtual Machine (Optional)

Note: The installation of a full-fledged IDE is optional. This part of the setup instructions is not part of project 1. In fact, it will not be required for any part of the course. Many developers just use their favorite editor (emacs, vim, sublime, etc.) for Ruby. The choice, however, is yours.

Two good IDEs are JetBrains' RubyMine (popular for Ruby development) and Microsoft's Visual Studio Code (aka VSCode, not to be confused with Microsoft's Visual Studio).
JetBrains offers a free license for students. VSCode is free for everyone. Pick one.

  1. RubyMine (JetBrains)

    1. Create a student account with JetBrains at www.jetbrains.com/student.

    2. Download and install the RubyMine IDE.

       $ sudo snap install rubymine --classic
      
    3. Run it:

       $ rubymine
      
    4. When you run RubyMine, you will be prompted to activate your (free) license by entering your JetBrains student account information.

  2. VS Code (Microsoft)

    1. Install the IDE.

        $ sudo snap install code --classic
      
    2. Configure the IDE (see the docs) and install extensions to help with web development.