# Setting up multiple versions of Ruby with the cPanel Ruby Selector

> Use the cPanel Ruby Selector to set up one or several Ruby versions for your applications on shared hosting.

Source: https://helpcenter.ruachost.com/developers/programming-languages/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 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

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).

3. Choose a version to use.
4. Create a directory for local gems:

```
mkdir -p ~/ruby/gems
```

5. 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
```

6. Update your environment:

```
source ~/.bash_profile
```

7. Check the Ruby version:

```
ruby -v
```

### 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.

### Using the Ruby environment

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 [~]#
```

4. Confirm the Ruby version:

```
ruby -v
```

5. Exit the environment:

```
deactivate
```
