Resource: Getting Started: First Steps in Ruby/Rails Development Google Slides
Instructions for Configuring Your Machine
You will have to do the following steps:
- Install an editor. You can use VSCode or Atom, and there are others as well.
- Install git if it is not already present. Your system will probably already have this.
- Install your ruby/rails environment.
In the next sections, there are specific descriptions on how to set up your machine. Depending on your specific machine configuration, there may be differences in what you need to do. If you have trouble, ask via Slack on how to get around it.
There are specific steps for installation on
- Linux Ubuntu
- Mac OSX
- Windows 10 (you must have at least 8G of memory)
If you do not have a machine of this description — for example, if your Windows machine only has 4G of memory — you will not be able to do local Rails development on your machine. Put a message in Slack and we will consider alternatives.
After you have configured your machine for Rails, verify your configuration. See the section at the bottom of this page.
Linux Setup on Ubuntu
This information is for Ubuntu. The same steps can be done on other Linux distributions, but you have to use different installation tools.
For rails environment installation, you can follow the instructions here: https://teamtreehouse.com/library/installing-rails-on-linux . With one important change! The instructor recommends ruby 2.3.1. This is too old. Specify ruby 2.6.5.
Mac OSX Setup
To install Ruby and Rails on the Mac, you can follow the instructions here: https://teamtreehouse.com/library/installing-a-rails-5-development-environment-on-mac With the following exceptions! To install rvm, after you install gpg, you need to install two gpg keys, not just one. The entire line is
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Update! the hkp protocol uses a non-standard port, which may be blocked by some firewalls. If the command above times out, try:
gpg --keyserver hkp://pool.sks-keyservers.net:80 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Sometimes, that key server doesn’t respond, in which case you could try one of these, perhaps with the :80 at the end:
- hkp://ipv4.pool.sks-keyservers.net
- hkp://pgp.mit.edu
- hkp://keyserver.pgp.com
After you install rvm and get the new terminal window, run
rvm install 2.6.5
rvm use 2.6.5 --default
Then you can install Rails 5.0.0 as described in the video. Note that you do not have to install a javascript engine, as this is built into Mac OSX.
Windows 64Bit Setup
DO NOT follow the Treehouse video on how to set up Rails on Windows. It is too old and no longer works.
We are going to set up a Linux virtual machine on Windows. The Linux virtual machine already has Ruby, rvm, node.js, bundler, and rails, and the other packages you need. This is a minimal virtual machine, so that it uses little memory. It has no GUI.
- Install VirtualBox from https://www.virtualbox.org/ . These steps are tested with VirtualBox 6.1.12, but you can install the latest version. Take the defaults for the installation options.
- Install Vagrant https://www.vagrantup.com/ . These steps are tested with Vagrant 2.2.9, but you can use the latest version. Be sure you install the 64 bit version. The installation is slow, so be patient. You will be given one or several security warnings, but proceed with the install. You will have to reboot your machine following the install.
- Download rails-ctd_1_1.box . You may get a security warning, but download it anyway. The download takes a long time.
- Open Git Bash. You will have a shortcut on your desktop to open it. Type the following:
- cd ~
- mkdir rails-ctd
- Move the rails-ctd_1_1.box file from your downloads folder into this new rails-ctd folder. In the File Explorer left hand pane, there is a person icon with your name. Open that up to find the rails-ctd folder. You will need to know how to find this folder when you use Atom or your preferred editor.
- Within your Git Bash session, type:
cd ~/rails-ctd
vagrant box add ./rails-ctd_1_1.box --name rails-ctd_1_1
vagrant init rails-ctd_1_1
This completes the Windows install and setup.
Windows: Using the rails-ctd Virtual Box and Git for Windows
Each time you use the development environment you have just set up, you do these steps.
- Start Git Bash
- cd ~/rails-ctd
- vagrant up
- Notes: this will take a little while. You can leave the virtual box running, even when you sleep the box, to save time.
- You will see several messages, including one about the guest additions version not matching. You can ignore that message.
- vagrant ssh
This starts the environment and takes you to a linux command shell. You can type rails –version to make sure it is working. If you don’t get this far, ask for help on Slack.
There are three parts to the Windows development environment.
- The vagrant ssh linux environment. This is where you will do all of your rails, ruby, bundle, irb, git and gem commands.
- Git Bash. This is where you will do all your vagrant commands.
- Your editor.
- You do not use the Windows command prompt.
Be sure you are in the right command environment when you do command line operations. You can have multiple Git Bash windows open concurrently. You can also have multiple vagrant ssh windows open for one vagrant virtual box. You exit vagrant ssh by typing exit. You exit Git Bash the same way.
You do git commands from the vagrant ssh linux environment. You should configure this environment as follows:
git config --global core.eol lf
git config --global core.autocrlf input
You must be in the Git Bash ~/rails-ctd directory to do vagrant commands.
To stop the virtual box, type: vagrant halt .
Verifying your Rails Installation
To verify that your environment is working correctly, we are going to create a sample rails application. For MacOS or Linux, open a command window or terminal and go to the directory where you are keeping your code. On Windows, open the vagrant ssh environment. Then type
rails new sample1
This will create a sample1 directory and many files and folders within it. Do not start the rails application yet! It won’t run because of an sqlite3 problem.
Rails commands after you create the sample1 application are done from the sample1 directory. There is a bin/rails file there, which is used for rails commands for this sample application.
There is an incompatibility between the current version of the sqlite3 gem and Rails 5.0. We will specify an older version of the sqlite3 gem in the Gemfile. Edit this file, which is in the sample1 directory. Change the line that says
gem 'sqlite3'
To
gem 'sqlite3', '~> 1.3.6'
Then, go to the sample1 directory in your command window and type:
bundle install
You are now ready to start Rails. From the command line, in the sample1 directory, type:
(for Windows Vagrant)
bin/rails s -b 0.0.0.0
(or, for Linux or Mac)
bin/rails s
To preview your application, you go to your browser and type:
The browser window should show a graphic with “Welcome to Rails”. If this does not work, try to figure out why, asking for help if needed.