Rails: Install multiple versions using rbenv
Whenever I need to install different versions of Ruby and Rails, I use to manage my Ruby packages and this post will show you how to use it too.
Ruby package managers enable you to install multiple versions of Ruby. The two most popular products are Ruby Version Manager (RVM) and Rbenv. This article is for developers who want to use
Step 1 - Install Ruby
You first need to install the right version of Ruby for your app. If you are working with an existing rails project, the easiest thing is to look at the
For example, here is the
Gemfile of a sample Rails 4 app for Heroku. It requires Rails
4.2.3 and Ruby
List all available versions of Ruby for
rbenv install --list-all
List all available versions of Ruby within a specific version.
rbenv install --list-all | grep 2.2
List only stable releases for
rbenv install --list
rbenv install 2.2.1
rbenv installs Ruby, run this.
You can double-check your work by asking rbenv to list which versions of Ruby you have installed.
Step 2 - Install Rails
Now let's tell rbenv which version of Ruby to use when installing rails.
RBENV_VERSION=2.2.1 rbenv exec gem install rails --version 4.2.1 --no-ri --no-rdoc
We are skipping the documentation
--no-rdocto speed up the installation process.
Step 3 - Create a Rails app
Create a new version of rails using a specific version of Ruby.
RBENV_VERSION=2.2.1 rbenv exec rails _4.2.1_ new [my_rails_4_app]
Step 4 - Set your local Ruby version
Change the directory to your project.
Set the local Ruby version.
rbenv local 2.2.1
Local enables you to keep your global version of Ruby yet use
4.2.1 on this local app.
Step 5 - Start Rails web sever
You can upgrade rbenv and ruby-build using Homebrew by running the following command:
brew upgrade rbenv ruby-build
- Jetbrains 2019 Survey on which version of Rails is most popular
- Rbenv Cheatsheet
- How to install rbenv on OSX
- All Versions of Rails - This will help you determine which version on rails you'll need.
- Heroku Rails 5 sample
- Heroku Rails 4 sample
- Openshift Rails 4 sample