Dept. of Computer Science & Engineering

Setting up the Development Environment on Windows

Last updated: Sept 8, 2023

The following guide is based on Windows 10. Your machine must meet the WSL 2 requirements.

Overview

Using WSL, you will install a linux distribution on your Windows machine. The two operating systems will run side-by-side, but there will be a new file system, distinct from the Windows C: drive. Your source code will be stored on the linux side, not the Windows side (e.g. \\wsl$\Ubuntu-22.04\home\jdoe\rails_work\demo, not C:\Users\JDoe\Documents\rails_work\demo). Build tools and commands like rails will run in linux, while your IDE (and browser) will run in Windows.

  1. Enable WSL 2 and Install Ubuntu
  2. Customize the Ubuntu Installation
  3. Install Ruby and Rails (in Ubuntu)
  4. Install Chrome and VS Code (in Windows)

Step 1: Enable WSL 2 and Install Ubuntu

  1. Assuming your machine meets the requirements, install Ubuntu using WSL. Enter the following command in an administrator PowerShell and then restart your machine:

    > wsl --install -d Ubuntu-22.04
    
  2. Open the Ubuntu distribution from the Start menu. When prompted, create a username (e.g. jdoe) and password.

  3. Install Windows Terminal from the Microsoft Store.

Step 2: Customize the Ubuntu Installation

The following customizations should be done within the Ubuntu distribution. That is, first open a terminal in Ubuntu either with the Windows Terminal or via the Start menu.

  1. Update the distribution:

    $ sudo apt update
    $ sudo apt upgrade
    
  2. Create an SSH private-public key pair to facilitate logging in to remote machines without typing a password. Copy the command below, customizing login@hostname with your own information.

    $ ssh-keygen -t ed25519 -C "login@hostname"
    

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

Step 3: Install Ruby and Rails (in Ubuntu)

  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
    

    After installation, reload the terminal for the changes to take effect.

  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 3.3.3 # this step takes several minutes
    $ rbenv global 3.3.3  # set default ruby version
    $ ruby -v # confirm it works
    
  3. Install Rails.

    $ gem install --no-document rails -v 7.0.8
    
  4. Confirm Rails installation with a simple smoke test.

    $ mkdir rails_work
    $ cd rails_work
    $ rails new demo
    $ cd demo
    $ rails server
    

    The output of the last command should look something like:

    => Booting Puma
    => Rails 7.0.8.y application starting in development 
    => Run `bin/rails server --help` for more startup options
    Puma starting in single mode...
    * Puma version: 5.6.8 (ruby 3.3.3-pxx) ("Birdie's Version")
    *  Min threads: 5
    *  Max threads: 5
    *  Environment: development
    *          PID: 18440
    * Listening on http://127.0.0.1:3000
    * Listening on http://[::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
    
  5. Install Node (not needed for Rails, but we'll be using it too).

    $ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
    $ source ~/.bashrc
    $ nvm install 20 --lts
    

Step 4: Install Chrome and VS Code (in Windows)

These customizations are done on the Windows side.

  1. (Optional) Install Chrome. (This step is optional because Edge can be used instead.)

  2. Install VS Code.

    1. Download and install VS Code for Windows.

    2. Watch the first few overview videos to learn your way around the IDE.

    3. Install some useful extensions: