How to setup Windows to begin developing Ruby on Rails Web Applications
Last updated: April 20, 2021 // Click here to go back to the tutorial series overview page.
Getting your local computer setup for developing web applications is one of the most difficult aspects of learning. In this tutorial, we will go all the way from a generic Windows 10 install to having a running Ruby on Rails application that you can see in a web browser on your machine. (FYI: If you are on a Mac, follow this tutorial instead.)
Here is a screencast of the walk-through I did with Isaac (14yr-old) that may be helpful for you as you work through the steps below (feel free to come back to it, perhaps, if you get stuck below. Otherwise, we do talk about misc things related to software development as well from an education standpoint.).
Let’s get started:
- Install Windows Subsystem for Linux by opening Powershell “as an Administrator”. If you are a younger student, you may need to have a parent/guardian do this for you or give you Administrator access for your Windows user.
- Copy, paste, and enter the following two lines in Powershell (each as a single line):
- dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
- dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- If you run into any errors on either of these two lines, visit this page on Microsoft’s website and follow the instructions to get things setup. Specifically, you may also need to enable virtualization on your machine if you get errors saying you need to.
- Restart your computer
- As an admin user again, open Powershell and enter the following:
- wsl --set-default-version 2
- If you run into any errors with this command, visit this page again on Microsoft’s website and follow instructions.
- Visit this page to install Ubuntu (it’s free)
- Note: if you haven’t entered passwords in a unix shell before, FYI, it doesn’t print out the characters when you are typing. This often confuses new users who think nothing is being entered, but this experience is designed on-purpose for security reasons.
- After installing, open Ubuntu from the start menu (or you can enter “wsl” in Powershell) and get things setup. I’d recommend just using your first name, all lowercase, for your username. You’ll want to remember the username and password that you set up, as that will be the password you’ll use when we run the “sudo” command later on.
- From here you’ll want to use your Ubuntu terminal for all the following commands.
- First, we’re going to ping Google to make sure you can resolve hostnames properly
- ping google.com
- (press control-C to stop the pings, which means it’s working correctly)
- If you got an error from the ping command, you are going to need to follow this tutorial to get things working.
- Start by getting some core things updated and installed (“apt-get” is a “package” manager that allows anyone to easily and magically install things):
- sudo apt-get update
- sudo apt-get install git-core curl 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
- Next we are going to install Ruby Version Manager (as of this writing, Ruby 3.0.0 is the latest version, but you should quickly double check and replace 3.0.0 below with the latest version number)
- sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
- gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
- curl -sSL https://get.rvm.io | bash -s stable
- source ~/.rvm/scripts/rvm
- rvm install 3.0.1
- rvm use 3.0.1 --default
- ruby -v
- That last command should output “3.0.1” and you’ll be all set.
- Finally, install the Ruby package manager called “Bundler”
- gem install bundler
- Now we’re going to get a code version control program called “Git” setup. The first thing you should do is go register for an account (free) at GitHub.com.
- In your terminal, enter the following, replacing in your details:
- git config --global color.ui true
- git config --global user.name "REPLACE WITH YOUR NAME"
- git config --global user.email "REPLACE_WITH_YOUR@EMAIL.com"
- ssh-keygen -t rsa -b 4096 -C "REPLACE_WITH_YOUR@EMAIL.com"
- (press enter to use defaults and to not set a password)
- Press enter to accept the default file name, and press enter again to not use a password.
- Then enter this:
- cat ~/.ssh/id_rsa.pub
- Copy that output key and paste it into your GitHub account here.
- Run the following command in your terminal to ensure it worked:
- ssh -T git@github.com
- You’ll see a successful message, and a note about Github not providing shell access (which is fine, you can ignore that).
- Next we need to install Node and Yarn, these are JavaScript package managers that Rails needs:
- sudo apt-get install -y nodejs yarn npm
- curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
- And finally, install the latest version of Rails (double check here, don’t use any that say “rc” in them...those stand for “release candidates”)
- gem update --system
- gem install rails
- Entering this command should reveal the version that you installed
- rails -v
- Now we’re going to install our database software called PostgreSQL
- sudo apt install postgresql postgresql-contrib
- Be sure to enter the command it tells you to run your postgres server. Remember this command, since you’ll need to use it to start your postgres server in the future as well.
- sudo pg_ctlcluster 12 main start
- We also need to create a super user to connect to our database, be sure to name the user the same name as your ubuntu user. Be sure to say yes to the user being a superuser - and remember the password you put in.
- sudo -u postgres createuser --interactive --pwprompt
- You’ll also need to install this so Rails will play nice with Postgres
- sudo apt install libpq-dev
- From your home directory in the WSL Ubuntu terminal (which is where you will be by default), let’s go ahead and create an “apps” folder where you will house all your code for apps you build
- mkdir apps/
- cd apps/
- Now create your Rails app, move into that directory, and set permissions on your bundle file correctly
- rails new quotesapp -d postgresql
- cd quotesapp
- Back in your Ubuntu terminal, run these commands to setup your database and Rails server:
- rake db:create
- rails s
- You should now be able to open your web browser (use Chrome) and visit http://localhost:3000 and see your new Rails app live. (Yay!)
- Important FYI: when you “rails s” it spins up a web server in your terminal and it will take over the inputs until you exit the server.
- As a final step, go ahead and install the code editor VSCode, which is a fantastic open source code editor by Microsoft that we’ll be using in this tutorial series.
If you have problems (or see anything above that needs updating), feel free to reach out to me directly at will@wclittle.com. Thanks!
Continue to the next part of the series → Full-stack web development "Hello World" tutorials for entrepreneurs :: Part 1 of 8