Setting up a Rails development environment in Ubuntu is something I frequently do, so rather than reaching for Google each time, I’ll keep a record here. I’ll be setting up Ruby using RVM, Rails, MySQL server, RubyMine and vim-rails. All commands are entered from a bash terminal. You can copy and paste the commands from this post into terminal.
Ensure you have build essentials installed:
Next, install our dependencies:
Ruby Version Manager (RVM)
RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems. Before we can install it, we need to obtain a key using GnuPG 2.0. First make sure GnuPG is installed:
Now obtain the key:
If you have problems installing the key, or the next step fails, don’t worry, the error message from the next step will give alternative instructions on how to get the key. Assuming everything is okay, let’s push on and grab RVM.
Once RVM is installed you need to modify your .bashrc file which is located in your home folder, using the editor of your choice. I’ll be using vim here:
Append to the bottom of the file the following before saving and exiting:
Exit your terminal and open it again so the .bashrc file gets reloaded, then enter the following command to install rvm dependencies – if you see a colon symbol (:) you will need to enter your password.
We are ready to install ruby. Head over to the official site to find the latest version of Ruby, as of this writing it is 2.4.1 so I’ll be installing that:
Instruct RVM to use 2.4.1 and set it as the default version of Ruby:
Now if you type ruby -v you should see 2.4.1.
Okay, let’s push onto installing Rails. Again, visit the official site to ascertain the latest version, as of this writing it is 5.1.2.
Why we are at it, we’ll install the MySQL2 gem:
Once that is finished, type rails -v and you should see 5.1.2. That’s it! Rails is up and running and good to go. Next we will configure our editors.
Update: Before proceeding you should now install Yarn and ChromeDriver, see here.
RubyMine is a very capable commercial IDE for Ruby that comes with a 30 day evaluation. I appreciate all the help I can get when developing, so RubyMine is my first choice for Rails development. Head over to JetBrains and download a version for Linux. I typically install 3rd party applications into a folder called Apps in my home directory, so I copy the downloaded file there. Assuming the name of the file is rubymine-2017.1.5.tar.gz I will uncompress it and rename it to rubymine:
Now to install it, we need to execute the rubymine script in the bin folder:
This will launch the graphical installer which is simple enough to follow, just remember to select the Evaluate for Free option on the licensing page. Once RubyMine is installed, you can begin editing your rails project by opening the folder from the RubyMine main screen.
Lastly, if you enjoy using vim, there is an excellent plugin available for Rails development from Tim Pope here. Assuming you have not configured vim yet you can execute the following instructions to install pathogen and vim-rails:
Initial .vimrc Settings
Next, edit your ~/.vimrc file (vim ~/.vimrc) and add the following:
Finally we can install vim-rails:
That’s it we are all up and running!