I wrote this article as a way to help my fellow microverse students. This may also help anybody interested in learning Rails.
Currently, The Odin Project uses an older version of Rails (5.2.3). Installing this older Rails version is easy. But as Rails 6 catches on, the older version is bound to fall out of use.
It took me quite a while to figure out how to do this on my own. This article is meant to save you a couple of hours. That way you can get to work on the fun stuff sooner!
Anyway, here’s how I installed Rails 6:
You can follow the Virtual Machine installation guide from The Odin Project to set up your preferred Ubuntu distro. You can also install Ubuntu on a real machine if you prefer.
The Ruby installation guide from The Odin Project currently uses Ruby 2.6.5. For Rails 6 we can install up to Ruby 2.7. However, Ruby 2.7 has been known to cause warning messages when used with Rails 6.
If you don’t really need the latest Ruby version, you can use 2.6.3 instead. This might save you a few warning messages later on as you work with rails.
Open your terminal, and run the following set of commands
$ sudo apt-get update $ sudo apt-get install curl git nodejs gcc make libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev g++ libpq-dev $ git clone https://github.com/rbenv/rbenv.git ~/.rbenv $ echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”’ >> ~/.bashrc $ echo ‘eval “$(rbenv init -)”’ >> ~/.bashrc $ exit
These will install rbenv and close your terminal window. You will need to open a new terminal window for the PATH changes to take effect.
To install Ruby 2.7.0, open a new terminal, and enter these commands:
$ mkdir -p “$(rbenv root)”/plugins $ git clone https://github.com/rbenv/ruby-build.git “$(rbenv root)”/plugins/ruby-build $ rbenv install 2.7.0 --verbose $ rbenv global 2.7.0
This is probably the most time-consuming part of the HOWTO, so be patient. Once Ruby is done installing, you’ll be ready for the next step.
This step is pretty straight-forward. Instead of installing the older version of Rails, as detailed in The Odin Project Guide, we’ll simply install Rails 22.214.171.124:
$ gem install rails -v 126.96.36.199
When I first tried to install Rails 6 on my virtual machine, I thought the previous step would be all there was to it. But I was wrong! At this point, if you try to run something like rails new my_first_rails_app you’ll get a series of error messages.
To fix this, you’ll have to install these recent versions of the following components:
To install the nodejs version required by Ruby 6, run:
$ curl -sL https://deb.nodesource.com/setup_12.x |sudo -E bash - $ sudo apt-get install -y nodejs $ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Bundler will allow you to load the necessary dependencies from Gemfiles, which are used by Rails apps. Pg is a Ruby gem you’ll need to communicate with PostgreSQL.
To install these, do:
$ gem install bundler:2.1.4 $ gem install pg
You will need yarn to be able to run rails server and test your Rails 6 apps. To install the necessary version, run:
$ echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list $ sudo apt update && sudo apt install yarn $ yarn install --check-files
Finally, you’ll want to make sure everything works as intended. To do this, I suggest you clone my Toy App Github repository and run some tests on it. This repository contains one of the first Rails exercises we did from The Odin Project at microverse:
$ git clone https://github.com/voscarmv/toy_app $ cd toy_app $ bundle install $ rails db:migrate $ rails server
This should serve the Toy App homepage to http://localhost:3000/ Play around with it and see how it works.
NOTE: If you run into errors when running bundle install, try running yarn install --check-files again. That will likely fix the problem.
You might be getting warning messages when running
or any other rails command. I suggest you point to the 6-0-stable branch of the rails 188.8.131.52 gem in your Gemfile.
Your Gemfile should look something like this:
I hope this HOWTO helped you save some time. If you run into trouble while trying it out, leave a comment or contact me on Twitter. I’ll do my best to help you out!
Finally, a special thank you to my coding partner Alexis for helping me find most of the commands from Step 4. I wouldn’t have been able to finish this guide so soon without his help!