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.
Setting up one Ruby version
Section titled “Setting up one Ruby version”To set up one Ruby version for command line use, follow these steps:
- Log in to your account using SSH.
- View available Ruby versions:
ls /opt/alt | grep rubyExample output:
ruby18/ruby19/ruby20/ruby21/ruby22/ruby23/ruby24/ruby25/ruby26/The two digits represent the version number (e.g., ruby26 is Ruby 2.6).
- Choose a version to use.
- Create a directory for local gems:
mkdir -p ~/ruby/gems- Edit the
~/.bash_profilefile and add these lines, replacingruby26with 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 RUBYHOMEexport GEM_HOMEexport GEM_PATHexport GEM_SPEC_CACHEexport PATH- Update your environment:
source ~/.bash_profile- Check the Ruby version:
ruby -vSetting up multiple Ruby versions with the Ruby Selector
Section titled “Setting up multiple Ruby versions with the Ruby Selector”- Log in to cPanel.
- In the Software section, click Setup Ruby App.
- Select the Ruby version you want.
- Enter an application name in the App Directory field.
- Select a domain in the App Domain/URI list.
- Optionally enter a path.
- 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 BEGINPassengerAppRoot "/home/example/myapp"PassengerBaseURI "/"PassengerRuby "/home/example/rubyvenv/myapp/2.6/bin/ruby"# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION ENDIf Ruby is not being used for the website, these lines should be removed.
Using the Ruby environment
Section titled “Using the Ruby environment”- Copy the Command for entering the virtual environment from cPanel.
- Log in using SSH.
- Run the command to activate the environment:
source /home/example/rubyvenv/myapp/2.6/bin/activatePrompt example:
(myapp:2.6)example@example.com [~]#- Confirm the Ruby version:
ruby -v- Exit the environment:
deactivate