You will have to do the following steps:
- Install an editor. You can use VSCode or Atom, and there are others as well. These instructions assume that you already have an editor.
- Install git if it is not already present. These instructions assume that you already have git.
- Install your Ruby/Rails environment, as described below.
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, and you must have administrator access)
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.
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.
First, install rbenv. At a terminal command line, enter the following commands:
sudo apt-get update
sudo apt-get install rbenv
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Then close your terminal window and open a new one. Then type these commands.
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
rbenv install 3.0.1
rbenv rehash
rbenv global 3.0.1
Then verify your installation with the following command.
ruby --version
The last command should return ruby 3.0.1 with some other things following. If you do not see ruby 3.0.1 STOP. You do not have ruby or rbenv installed correctly. Go back and retry the previous steps, or put a message in the slack channel.
Then enter the following commands:
gem install bundler
gem install rails -v 6.1.3
rbenv rehash
sudo apt-get install yarn
You also need to have node.js installed. This is often done on Linux using nvm. To install nvm and node, enter the following commands.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.profile
nvm install node
If you get a command not found, close your terminal session, open a new one, and retry the command. Verify your node installation using:
node --version
Now, verify the Rails installation by creating a sample rails server. Enter the following command:
rails new sample1
This will run for quite some time, and will create a directory called sample1 with many files and folders. Then type the following commands:
cd sample1
bin/rails server
This will start the server. You can now verify that the server is running by going this link: http://localhost:3000 . You should see a “Yay! You’re on Rails” screen, reporting a Rails version of 6.1.3 and a Ruby version of 3.0.1. If you don’t get this far, put a message in the slack channel. If you do get this far, go back to your command line and press Ctrl-C to stop the server.
Mac OSX Setup
If your Mac has the M1 chip, you should do your development in a Rosetta terminal session.
See https://osxdaily.com/2020/11/18/how-run-homebrew-x86-terminal-apple-silicon-mac/
These steps assume that you have Homebrew installed. If you do not have Homebrew installed,
see this link for installation instructions: https://brew.sh/ You can check to see whether
you have Homebrew installed by opening a terminal window and typing brew –version.
First, install rbenv. At a terminal command line, enter the following commands:
brew install rbenv
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
Then close your terminal window and open a new one. Then type these commands:
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
rbenv install 3.0.1
rbenv rehash
rbenv global 3.0.1
Then verify your installation with the following command.
ruby --version
The last command should return ruby 3.0.1 with some other things following. If you do not see ruby 3.0.1 STOP. You do not have ruby or rbenv installed correctly. It will not work to run a different Ruby version. Go back and retry the previous steps, or put a message in the slack channel.
Then enter the following commands:
gem install bundler
gem install rails -v 6.1.3
rbenv rehash
brew install yarn
You also need to have node.js installed. You can install this as follows
brew install node
Verify your node installation using:
node --version
Now, verify the Rails installation by creating a sample rails server. Enter the following command:
rails new sample1
This will run for quite some time, and will create a directory called sample1 with many files and folders. Then type the following commands:
cd sample1
bin/rails server
This will start the server. You can now verify that the server is running by going to this link: http://localhost:3000 . You should see a “Yay! You’re on Rails” screen, reporting a Rails version of 6.1.3 and a Ruby version of 3.0.1. If you don’t get this far, put a message in the slack channel. If you do get this far, go back to your command line and press Ctrl-C to stop the server.
Windows 64Bit Setup.
We are going to set up a Linux virtual machine on Windows. The Linux virtual machine already has Ruby, rbenv, node.js, bundler, yarn, rails, and the other packages you need. This is a minimal virtual machine, so that it uses little memory. It has no GUI.
These instructions assume that you already have git bash installed. If not, install it from here: https://gitforwindows.org/ Note: When you install git bash, you must click the box to enable symbolic links. If not, you will get an error saying that a symbolic link failed when you run yarn install. If you get this error (you will not see it until lesson 6, when you have to run yarn install), re-install git for windows and click this box.
- 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_2_0.box . You may get a security warning, but download it anyway. The download takes a long time. Be sure you have a good internet connection when you do this.
- 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_2_0.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_2_0.box --name rails-ctd_2_0
vagrant init rails-ctd_2_0
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. Note: You MUST start it using Run as Administrator. One way to do this is to right click on the Git Bash icon and select Run as Administrator. This is necessary because Rails 6 uses a package called yarn which requires symlinks. Symlinks don’t work under vagrant unless you run as administrator.
- 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 may 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. 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, you would type: vagrant halt — but don’t do that just yet.
To verify that your environment is working correctly, we are going to create a sample rails application. On Windows, open the vagrant ssh environment. Then type
rails new sample1
This will run for quite some time, and will create a directory called sample1 with many files and folders. Then type the following commands:
cd sample1
bin/rails server -b 0.0.0.0
This will start the server. Please note that you must include the -b 0.0.0.0 when you are running on vagrant. You can now verify that the server is running by going to this link: http://localhost:3000 .You should see a “Yay! You’re on Rails” screen, reporting a Rails version of 6.1.3 and a Ruby version of 3.0.1. If you don’t get this far, put a message in the slack channel. If you do get this far, go back to your command line and press Ctrl-C to stop the server.
A note about using vagrant: One big disadvantage is that if you make changes to your Rails code, you must stop and restart the rails server for the changes to take effect. This is because you are changing code in the Windows session but running it in the Linux session. Remember this!