▶️ Play from the beginning (~30 minutes)
In this demonstration, I will show you how to setup the development environment used in the rest of the demos. The following setup should generally work for Windows, Mac, and Linux.
Before I jump into the demo, I’d like to clear up a little terminology. In these demos, I will be using a virtual machine (VM). A VM is where one OS is run inside of another OS (rather than directly on a physical machine). The parent OS is called the host OS. For example, imagine you have a Windows computer—that’ll be the host OS. You can use the VirtualBox software to install a Linux OS within the host Windows OS and to run a Linux VM as if it were a Windows program.
▶️ Register an account at https://github.com/ (if you don’t already have one). Git and GitHub will be used for version control and collaboration in these demos. Be sure not to lose your GitHub username and password.
Rails
Ruby
erb
markdownlint
Markdown PDF
Code Spell Checker
▶️ Install a Bash shell with SSH client (if you don’t already have it). Windows users, download and install the Git for the Windows platform (http://git-scm.com/download/win), which comes with a Bash shell and SSH client. MacOS users have this software by default (see the Terminal app). Debian/Ubuntu Linux users have the shell, but may need to install the “openssh-client” package (if it’s not already installed by default).
▶️ Download and install VirtualBox (https://www.virtualbox.org/). I will be using this software to run an Ubuntu Linux virtual machine. This VM will house the majority of the Rails development tools. In essence, the development environment in these demos will mainly be on Ubuntu Linux (with some graphical software running in the host OS).
▶️ Create a folder workspace
. This folder is where all the Rails projects in these demos will go.
workspace
folder. Make sure that no file suffix (e.g., “.txt”) gets added to the Vagrantfile when saving it. For example, one way to download it would be to right-click on the hyperlink and select “Save Link As…” (or similar) from the context menu.
▶️ Launch a terminal. In Windows, it involves launching Git Bash. In MacOS, this involves launching the Terminal app. I assume that Linux users need no clarification here.
▶️ In the terminal, change directory (using the cd
command) to the workspace
folder. Note: I will be using the command-line a lot in the demos. I will generally assume that readers are familiar with the basic file management and navigation commands (cd
, rm
, cp
, mv
, etc.). If you’re new to the command-line, I highly suggest you spend some time on your own learning about it—for example, Codecademy has a course: https://www.codecademy.com/learn/learn-the-command-line.
vagrant up
to download and initialize a Vagrant box. BEWARE! This command (1) may take a long time to complete, (2) downloads a big file (~700MB), and (3) performs at least one processor-intensive compilation (of Ruby). Once this command completes, you will have a running Ubuntu Linux VM (headless).
▶️ Run the command vagrant ssh
to SSH into the Linux VM. A command prompt should appear that looks like this: [vagrant@ubuntu-xenial:~]
followed by a $
prompt. If you use the ls -l
command, you will see a list of files in the current directory. Among them should be a workspace
folder (actually a symbolic link to the folder /vagrant
).
▶️ Change directory (using the cd
command) to the workspace
folder. Note that this folder is synced with the workspace
folder on the host OS. That is, changes made in the folder on one side (VM or host OS) are instantly visible on the other side.
▶️ Enter the command git clone https://github.com/sdflem/sample_app.git
to use Git to download an example project. A sample_app
folder should be visible inside the workspace
folder. Note that the workspace
folder is synced with the host OS, so the sample_app
folder should also be visible in the host OS’s file explorer. The main reason for syncing this folder is that it will enable the use a GUI code editor (VS Code) to work on the code files.
▶️ Change directory (using the cd
command) to the sample_app
folder. When you run this command, RVM should print a message, which lets you know it’s working. If no such message appears, then something is wrong. A common problem is that the terminal application is not configured to run as a “login” shell. This issue seems to come up the most for Linux users, or users of more exotic terminal applications. Typically, the solution can be found in the terminal application’s settings.
gem install bundler -v '~> 1.17'
bundle install --without production
rake db:setup
▶️ The project comes with some automated tests. Run the command rake test
to execute the tests. You should see that all the tests passed.
▶️ Start up the Rails web app server with the command rails s -b 0.0.0.0
(those are zeros). You should see that the server has started without error. Note that this command will not “return” like other commands—that is, the command prompt will not reappear until you halt the server process (covered below).
▶️ Now open the URL http://localhost:3000 in a web browser. A “Welcome to the Sample App” web page should appear.
example@railstutorial.org
and the password foobar
. It should quickly become clear that this is a Twitter-like app. To create a post, click the “Home” link, and then enter and submit some text. The new post should appear at the top of the post stream.To shut down everything:
exit
to logout of the VM.vagrant halt
to shut down the VM.To restart the VM, run vagrant up
to start it up (should be much faster than last time) and run vagrant ssh
to log in again.