Site5 - Built For Designers & Developers MENU
Home  ›  Ruby & Ruby On Rails  ›  Ruby: How to setup a custom RubyGems environment

Ruby: How to setup a custom RubyGems environment

24 Comments

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

---
gem: --no-ri --no-rdoc
gemhome: /home/USERNAME/.gems
gempath:
- /home/USERNAME/.gems
- /usr/lib/ruby/gems/1.8
:benchmark: false
:update_sources: true
:verbose: false
:backtrace: false
:sources:
- http://gems.rubyforge.org/
- http://rubygems.org/
:bulk_threshold: 1000

2. Save the changes to the “.gemrc” file and close the file.

3. You can confirm the changes worked by running the command below to view your “live” Gem environment:

gem env

The output should look something like this:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.6.2
  - RUBY VERSION: 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/USERNAME/.gems
  - RUBY EXECUTABLE: /usr/bin/ruby
  - EXECUTABLE DIRECTORY: /home/USERNAME/.gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/USERNAME/.gems
     - /usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => false
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gempath" => ["/home/USERNAME/.gems", "/usr/lib/ruby/gems/1.8"]
     - "gem" => "--no-ri --no-rdoc"
     - :sources => ["http://gems.rubyforge.org/", "http://rubygems.org/"]
     - "gemhome" => "/home/USERNAME/.gems"
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/
     - http://rubygems.org/

 

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

# START
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
 
PATH=$HOME/.gems/bin:$HOME/bin:$PATH
 
GEM_HOME=$HOME/.gems
GEM_PATH=$HOME/.gems:/usr/lib/ruby/gems/1.8
 
export PATH GEM_HOME GEM_PATH
# END

2. Close the file and save the changes you made.

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:

# rails -v
Rails 3.1.0

Still have a question? Or need help?
If you need technical support with your account, please email us or chat live with a representative.

24 Comments

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

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

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

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

  • Great guide. That was my problem!

  • 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

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

      Happy Hosting!

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

    • 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

      http://blog.site5.com

      However, you can use a custom version of Rails and RubyGems. For more information about how to upgrade the version of Rails, please see the following link…

      http://www.site5.com/blog/programming/how-to-enable-rails-3-0-on-site5/20101007/

      For more information about how to setup custom RubyGems, please see the article above.

      In regards to your comment about rsync, could you please provide more details with what you are attempting to do?

      We look forward to hearing from you!

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

        01:22 PM basilking.net $ gem install singularitygs
        ERROR: While executing gem … (Errno::E045)
        Operation not supported – /home/artandde

        01:50 PM ~ $ gem install bundler –development
        ERROR: While executing gem … (Errno::ENOTSUP)
        Operation not supported – /home/artandde

        • Hello Lori,

          I hope this comment finds you well!

          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 [email protected]

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

  • 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…

    • Hi Michael,

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

  • HI

    I have tried installing ruby from source ,
    [user@host bin]$ ruby –version
    ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

    I have some doubts ,
    1. Do i need to add nano ~/.gemrc this before installing ruby ?
    2. please find my gem env
    [user@host bin]$ ./gem env
    /scratch/user/RUBY/lib/ruby/1.9.1/yaml.rb:56:in `’:
    It seems your ruby installation is missing psych (for YAML output).
    To eliminate this warning, please install libyaml and reinstall your ruby.
    RubyGems Environment:
    – RUBYGEMS VERSION: 1.8.11
    – RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
    – INSTALLATION DIRECTORY: /scratch/user/RUBY/lib/ruby/gems/1.9.1
    – RUBY EXECUTABLE: /scratch/user/RUBY/bin/ruby
    – EXECUTABLE DIRECTORY: /scratch/user/RUBY/bin
    – RUBYGEMS PLATFORMS:
    – ruby
    – x86_64-linux
    – GEM PATHS:
    – /scratch/user/RUBY/lib/ruby/gems/1.9.1
    – /scratch/user/.gem/ruby/1.9.1
    – GEM CONFIGURATION:
    – :update_sources => true
    – :verbose => true
    – :benchmark => false
    – :backtrace => false
    – :bulk_threshold => 1000
    – REMOTE SOURCES:
    http://rubygems.org/

    why do i get this below error when i have that file in [user@host ~]$ ls /usr/include/yaml.h
    /usr/include/yaml.h

    /scratch/user/RUBY/lib/ruby/1.9.1/yaml.rb:56:in `’:
    It seems your ruby installation is missing psych (for YAML output).
    To eliminate this warning, please install libyaml and reinstall your ruby.

    Please suggest a solution , i couldnt proceed further .

    • Hello LKrishnan,

      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

    • Hi Craig,

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


    gem: –no-ri –no-rdoc
    gemhome: /home/USERNAME/.gems
    gempath:
    – /home/USERNAME/.gems
    – /usr/lib/ruby/gems/2.4.6
    :benchmark: false
    :update_sources: true
    :verbose: false
    :backtrace: false
    :sources:
    http://gems.rubyforge.org/
    http://rubygems.org/
    :bulk_threshold: 1000

    2) The gem env command displays this:

    RubyGems Environment:
    – RUBYGEMS VERSION: 2.4.6
    – RUBY VERSION: 2.1.6 (2015-04-13 patchlevel 336) [x86_64-linux]
    – INSTALLATION DIRECTORY: /home/USERNAME/.gems
    – RUBY EXECUTABLE: /usr/local/rubies/ruby-2.1.6/bin/ruby
    – EXECUTABLE DIRECTORY: /home/lat23rad/.gems/bin
    – SPEC CACHE DIRECTORY: /home/lat23rad/.gem/specs
    – SYSTEM CONFIGURATION DIRECTORY: /usr/local/rubies/ruby-2.1.6/etc
    – RUBYGEMS PLATFORMS:
    – ruby
    – x86_64-linux
    – GEM PATHS:
    – /home/USERNAME/.gems
    – /usr/lib/ruby/gems/2.4.6
    – GEM CONFIGURATION:
    – :update_sources => true
    – :verbose => false
    – :backtrace => false
    – :bulk_threshold => 1000
    – “gem” => “–no-ri –no-rdoc”
    – “gemhome” => “/home/USERNAME/.gems”
    – “gempath” => [“/home/USERNAME/.gems”, “/usr/lib/ruby/gems/2.4.6”]
    – :benchmark => false
    – :sources => [“http://gems.rubyforge.org/”, “http://rubygems.org/”]
    – REMOTE SOURCES:
    http://gems.rubyforge.org/
    http://rubygems.org/
    – SHELL PATH:
    – /home/USERNAME/.gems/bin
    – /home/USERNAME/bin
    – /usr/local/jdk/bin
    – /home/USERNAME/perl5/bin
    – /usr/local/bin
    – /bin
    – /usr/bin
    – /usr/local/sbin
    – /usr/sbin
    – /sbin
    – /usr/local/bin
    – /usr/X11R6/bin

    3) I edited the ~/.bash_profile file to look like this:

    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

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

    GEM_HOME=$HOME/.gems
    GEM_PATH=$HOME/.gems:/usr/lib/ruby/gems/1.8

    export PATH GEM_HOME GEM_PATH
    # END

    4) I ran source ~/.bash_profile. No errors or any feedback at all. I presume that means it went okay.

    5) This went south when I ran this: rails -v; which rails:

    /usr/local/rubies/ruby-2.1.6/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:315:in `to_specs’: Could not find ‘railties’ (>= 0) among 16 total gem(s) (Gem::LoadError)
    Checked in ‘GEM_PATH=/home/lat23rad/.gems:/usr/lib/ruby/gems/2.4.6′, execute `gem env` for more information
    from /usr/local/rubies/ruby-2.1.6/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:324:in `to_spec’
    from /usr/local/rubies/ruby-2.1.6/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:64:in `gem’
    from /usr/local/bin/rails:22:in `’
    /usr/local/bin/rails

    6) I ran gem list and see this:

    activesupport (4.2.6)
    bigdecimal (1.2.4)
    builder (3.2.2)
    erubis (2.7.0)
    i18n (0.7.0)
    io-console (0.4.3)
    json (1.8.1)
    mini_portile2 (2.0.0)
    minitest (5.8.4, 4.7.5)
    psych (2.0.5)
    rake (10.1.0)
    rdoc (4.1.0)
    test-unit (2.1.6.0)
    thread_safe (0.3.5)
    tzinfo (1.2.2)
    [email protected] [~]#

    No railties, etc.

    7) So I then tried to install rails:

    ERROR: Error installing rails:
    ERROR: Failed to build gem native extension.

    /usr/local/rubies/ruby-2.1.6/bin/ruby -r ./siteconf20160406-75-991pvc.rb extconf.rb
    checking if the C compiler accepts … *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of necessary
    libraries and/or headers. Check the mkmf.log file for more details. You may
    need configuration options.

    Provided configuration options:
    –with-opt-dir
    –without-opt-dir
    –with-opt-include
    –without-opt-include=${opt-dir}/include
    –with-opt-lib
    –without-opt-lib=${opt-dir}/lib
    –with-make-prog
    –without-make-prog
    –srcdir=.
    –curdir
    –ruby=/usr/local/rubies/ruby-2.1.6/bin/ruby
    –help
    –clean
    /usr/local/rubies/ruby-2.1.6/lib/ruby/2.1.0/mkmf.rb:456:in `try_do’: The compiler failed to generate an executable file. (RuntimeError)
    You have to install development tools first.
    from /usr/local/rubies/ruby-2.1.6/lib/ruby/2.1.0/mkmf.rb:571:in `block in try_compile’
    from /usr/local/rubies/ruby-2.1.6/lib/ruby/2.1.0/mkmf.rb:522:in `with_werror’
    from /usr/local/rubies/ruby-2.1.6/lib/ruby/2.1.0/mkmf.rb:571:in `try_compile’
    from extconf.rb:80:in `nokogiri_try_compile’
    from extconf.rb:87:in `block in add_cflags’
    from /usr/local/rubies/ruby-2.1.6/lib/ruby/2.1.0/mkmf.rb:619:in `with_cflags’
    from extconf.rb:86:in `add_cflags’
    from extconf.rb:336:in `’

    extconf failed, exit code 1

    Not sure where to go at this point. I tried to go to that blog link listed above, but it’s a dead link now.

    Any help would be appreciated.

    Thanks!

    Tom

    Gem files will remain installed in /home/lat23rad/.gems/gems/nokogiri-1.6.7.2 for inspection.
    Results logged to /home/lat23rad/.gems/extensions/x86_64-linux/2.1.0-static/nokogiri-1.6.7.2/gem_make.out

    • Adding one more thing. This link re: the Bundler is broken as well:

      http://kb.site5.com/ruby-on-rails/installing-gems-using-bundler/

      Does the bundler even exist here?

      Thanks.

      • Hi Tom!

        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 …

          • Hi Tom!

            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 …

Money Back Guarantees