Ruby: How to setup a custom RubyGems environment

Why you need a custom RubyGems environment

If you want to add a RubyGem on your account, you will need to install it within your account. We don’t provide a global set of gems for Ruby 1.9.3 onwards, as the Ruby community standard is to manage gems locally, giving the developer full control of the gems available to the application. Most applications use Bundler to manage their gem dependencies – see this article on managing gems with Bundler for more information.

Notice: This guide does assume that you have some basic knowledge of logging in to your account via SSH, basic command line tools and at least one command line editor (vim/emacs/nano).

Configuring your RubyGems environment

1. The first step is to ensure that your “.gemrc” file is configured properly. Open it up in your text editor:

nano ~/.gemrc

(if the file does not exist, simply create a new empty file and we’ll add in the required contents) Your “.gemrc” file should look like the below (make sure you replace USERNAME with your actual Site5 username):

Updating your Bash environment to work with your RubyGems environment

The next step is to update our “.bash_profile” file so that if we install any RubyGems that include command line interfaces (binaries), we can run them easily without typing out the full path. This step will also set the GEM_HOME and GEM_PATH environment variables.

1. Open up your “.bash_profile” file in your favorite text editor:

nano ~/.bash_profile

If the file does not exist, create a new one and then make sure it contains the following (copy and paste everything from the #START to the #END lines):

3. In order to initiate the changes to your Bash environment, you need to run the following command:

source ~/.bash_profile

Install latest version of Rails gem

It’s possible that your server might not always have the latest version of Rails installed, but that is ok! It’s better to maintain the gem versions within your account so you have full control over what versions you are using. This ensures that you don’t ever have any surprises that could cause your applications to suddenly stop working due to an update or migration.

1. Firstly, let’s check the current version of Rails and where it’s installed by running the following command:

rails -v; which rails

The output may look something like the following, but the Rails version will likely be different:

Rails 3.0.1
/usr/bin/rails

As you can see, you are using the system “Rails” binary at “/usr/bin/rails” and soon we will be running our own Rails binary from within our home directory.

2. Now, let’s install our own version of Rails! If you want to get the latest version of Rails available, run the following command:

gem install rails

If you want to fetch a specific version of Rails, use the following syntax instead:

gem install rails -v 3.0.10

You should see something similar to the output below:

Successfully installed rails-3.1.0
1 gem installed

Save that, then run the following command to let the server know we changed things.

source ~/.bash_profile

3. If you run the “which rails” command it will show you the location of the Rails binary you are now using:

# which rails/home/USERNAME/.gems/bin/rails

4. You will also see that you are now using the latest version of Rails when you check a “rails -v” from the command line:

Still have a question? Or need help?See an error in this article or want to suggest a missing topic? Please leave us a comment below! If you need technical support with your account, please email us, chat live with a representative, or call us!

24 Comments

What about the situation if the app uses Bundler to maintain gem & dependencies to deploy path /vendor/bundle?

Graham McMillan December 28, 2011 at 8:06 am

If you’re using Bundler, you’ll just setup your Gemfile as you normally would. Your RubyGems environment is something completely separate for the most part. However, most people still need a properly configured RubyGems environment for RubyGems that include binaries or command line tools.

how about changing the Ruby itself, since next version of rails will drop support for Ruby 1.8.7.

joliver February 17, 2012 at 10:43 am

At this time, it is not possible for users to change what version Ruby is running. However, we do have plans to move to 1.9.x in the near future. Keep an eye on the official Site5 Blog (http://www.site5.com/blog/) for when that release happens.

Graham McMillan February 17, 2012 at 11:19 am

We would offer both versions of Ruby, but it’s not currently supported in Phusion Passenger (for customers to be able to switch back and forth like with RVM or rbenv). We need to pick one version for all customers and 1.8.7 has the greatest compatibility at the moment.

The guide had us add this line twice, once before and once after rails installation:

PATH=$HOME/.gems/bin/:$HOME/bin:$PATH

When I follow the directions and enter the source command, which rails gives me the same result as before:

Rails 3.0.1
/usr/bin/rails

Instead of the expected result:

/home/USERNAME/.gems/bin/rails

John Oliver at Site5 April 18, 2013 at 4:21 pm

Hello Joe,

I hope this message find you well!

I have updated this article with a few changes. If possible, would you please try following the instructions again?

The only way I was able to reproduce this was not replacing USERNAME with the correct username when editing the gemrc file. From there, so long as all the other steps are completed, the output should be as expected.

If you have any questions, or if anything is unclear, please feel free to leave a comment here. You can also contact our support department directly by opening a ticket through Backstage.

So it seems that I site5 can host a Rails app using ruby 1.9. or even 2.0? with rsync. So glad to hear that if so.

John Oliver at Site5 June 11, 2013 at 3:42 pm

Hello Lori,

I hope this comment finds you well!

The current Ruby version installed is 1.8.7 and unfortunately cannot be changed at this point in time.

We are locked to version 1.8.7 because that is the default version shipped with cPanel. We’re currently testing the new version of Phusion Passenger, which allows the use of multiple Ruby versions. Once we’ve put it through the paces, we’ll get it deployed fleet-wide and make a blog post announcing its availability on our servers

Actually, ever since I started with Rsync on Site5, everything is great with that particular project. But when I want to work on another project not hosted on Site5, and I try “gem install bundler” I get ‘not allowed at home/artandde/ so I am currently not able to install any other gems for local development use.

I am sorry to hear about the problems you are facing with bundler. Because of the nature of the issue, we ask that you open a ticket with our support department so that we can better assist you in troubleshooting this problem.

You can open a ticket either through Backstage or by emailing us directly at support@site5.com

We look forward to hearing from you and helping you resolve this issue.

Michael February 13, 2014 at 6:35 pm

Just a comment that the directory structure may not be the same as this article…I’m a reseller and not all that familiar with Ruby and gems, but I’m installing Compass and Sass, and while they installed ok, I was getting “command not found” errors on compass.

In the tutorial, it uses “.gems” in various places, but in my directory structure as I looked in File Manager, there was no .gems – things were in home/USERNAME/ruby/gems. So I changed every instance of .gems to ruby/gems, and things are working fine now.

I don’t know if this is a user-specific case or not, but I’m just commenting to share what I had to do to get it working…

That would be user-specific, yes. You would set the path during this process, and can set this to something not mentioned here, if you like (though I would not recommend doing so, as this follows standards that other things will expect).

I’m sorry for the troubles you are having. Based on the copy/paste information provided, though, it looks like you’re attempting this locally, on your workstation. Is that correct? If so, we would not be able to make any suggestions, as every environment is different.

If you run into any issues with this on our servers, however, we would be more than happy to help, though your best bet would be to open a ticket with our support team, via BackStage.

I’ve been having all kinds of trouble getting anything ruby to work. I’ll start here for now. I do the instructions on this page exactly trying to install rails 3.0.0.
The first issue is:
Running the command “source ~/.bash_profile” I get “line 13: syntax error: unexpected end of file”
All other commands seem to work without errors until I check the rails version and it hasn’t changed from 2.3.16

What is the entry on line 13 of your .bash_profile file? The syntax error is not due to the command, but something in that file – I would suggest you contact our support team on this, and we can take a look for you.

I’m trying to configure RoR following this guide, but perhaps because it’s been so long since this was written, they’re not correct. Here’s what I see.

1) I modified the .gemrc file a couple of times (one to match exactly like in the above example and another to reflect the current version of gems). It looks like this (I removed my real username for these listings, but trust me, it’s correct in my scripts):

I’m sorry to hear about the install issues you are running into. If you would please open a ticket with our support team through your backstage panel, we’ll be glad to dig in and locate the exact reason this is failing for you.

Regarding the Bundler link, that will be removed from this article due to the bundler instructions being removed from our KB recently. While bundler is still present, our newer server configurations did not work perfectly with the old instructions.

Okay, thanks, I’ll definitely open a ticket. Will this article (and the other linked articles, including on the bundler) be updated at any point to reflect the newer server configurations? For those of us new to Site5 — and for me, new to configuring a remote server for RoR — would benefit immensely from fresh content.

(As an aside, it took a bit to get my Mac running El Capitan to update and successfully run RoR flawlessly. I had to do a lot of research, aka Google searches, until I got it right. It’s do-able, but updated documentation would’ve cut the time down by a few hours).

One way or the other, I may blog my experience on my Mac and here to help other newbies. I just wish I kept notes …

Great! Our admins will help get everything all fixed up for you. Regarding the posts, I’m sure we will. We had quite a library of RoR articles previously but due to the conflicts with our newer server configurations, we needed to take them down until they can be updated. Getting the documentation re-written is quite a task so, we’ll be posting them up as we get them written!

Awesome regarding the documentation, thanks. Yes, issues have been addressed and resolved by the admins. There are other issues I’ll be either adding to this forum if the admins can’t resolve them. More to come …