Skip to content

Setting up multiple versions of Ruby with the cPanel Ruby Selector

Multiple versions of Ruby are available in cPanel when using CloudLinux and the Ruby Selector. This guide shows you how to set up one or more versions of Ruby.

Shared and reseller hosting accounts with cPanel and CloudLinux allow multiple Ruby versions. You can configure your account to use a single version or several. Instructions for both scenarios are provided below.

Note: These instructions apply to servers with cPanel and the Ruby Selector installed. Check for the Setup Ruby App icon in the Software section of cPanel before proceeding.

To set up one Ruby version for command line use, follow these steps:

  1. Log in to your account using SSH.
  2. View available Ruby versions:
ls /opt/alt | grep ruby

Example output:

ruby18/
ruby19/
ruby20/
ruby21/
ruby22/
ruby23/
ruby24/
ruby25/
ruby26/

The two digits represent the version number (e.g., ruby26 is Ruby 2.6).

  1. Choose a version to use.
  2. Create a directory for local gems:
mkdir -p ~/ruby/gems
  1. Edit the ~/.bash_profile file and add these lines, replacing ruby26 with your chosen version:
RUBYHOME="/opt/alt/ruby26"
ORIG_GEM_HOME=$("$RUBYHOME/bin/gem" --config-file "" env GEM_HOME)
GEM_HOME="$HOME/ruby"
GEM_PATH="$GEM_HOME:$ORIG_GEM_HOME"
GEM_SPEC_CACHE="$GEM_HOME/specs"
PATH="$RUBYHOME/bin:$PATH"
export RUBYHOME
export GEM_HOME
export GEM_PATH
export GEM_SPEC_CACHE
export PATH
  1. Update your environment:
source ~/.bash_profile
  1. Check the Ruby version:
ruby -v

Setting up multiple Ruby versions with the Ruby Selector

Section titled “Setting up multiple Ruby versions with the Ruby Selector”
  1. Log in to cPanel.
  2. In the Software section, click Setup Ruby App.
  3. Select the Ruby version you want.
  4. Enter an application name in the App Directory field.
  5. Select a domain in the App Domain/URI list.
  6. Optionally enter a path.
  7. Click Setup to create the application.

The Ruby Selector will add configuration lines to the .htaccess file for that domain:

# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/example/myapp"
PassengerBaseURI "/"
PassengerRuby "/home/example/rubyvenv/myapp/2.6/bin/ruby"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END

If Ruby is not being used for the website, these lines should be removed.

  1. Copy the Command for entering the virtual environment from cPanel.
  2. Log in using SSH.
  3. Run the command to activate the environment:
source /home/example/rubyvenv/myapp/2.6/bin/activate

Prompt example:

(myapp:2.6)example@example.com [~]#
  1. Confirm the Ruby version:
ruby -v
  1. Exit the environment:
deactivate