Site5  /  Backstage  /  Wiki  /  Site5 Support  /  Blog  /  Uptime Reports  /  Server Status Page
 

Go Back   Site5 Web Hosting Forums > Community Forums > Scripts and Programming > Ruby

Ruby Discussion of Ruby and all related code, and its usage and development, both on Site5 servers and elsewhere

Closed Thread
 
Thread Tools Rating: Thread Rating: 5 votes, 4.40 average. Display Modes
  #1  
Old August 15th, 2006, 08:14 PM
dusty.doris dusty.doris is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Aug 2006
Location: Cincinnati, OH
Posts: 3
Howto Install your own Gems for Rails

What you need to know:
- path to where you will store your local gems
eg: /home/yourusername/gems
- path to the base gems
eg: /usr/lib/ruby/gems/1.8

What you will do:
- Setup GEM_HOME which is where you will INSTALL new gems and GEM_PATH which is where you will FIND gems.
- Make the gem program, your shell, and rails know about your gems
- Install a gem
- Test to see if its working

How to do it:

1. ssh to your account
$ ssh yourusername@yourdomain.com

2. Make sure you are in YOUR home directory
$ cd ~

3. Find the path you are in
$ pwd
/home/yourusername

4. Find where the base gems are installed
$ gem environment
Rubygems Environment:
- VERSION: 0.8.10 (0.8.10)
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- GEM PATH:
- /usr/lib/ruby/gems/1.8
- REMOTE SOURCES:
- http://gems.rubyforge.org

5. Create a directory to install your local gems
$ mkdir gems

6. Create a .gemrc file in your home directory (~) to declare GEM_PATH and GEM_HOME for the gem program. This is in yaml format. Replace gemhome with the full path to where you will store the gems locally in your account. Replace the gempath with whatever the path is on your machine if its different.

$ vi .gemrc
# add what is below
gemhome: /home/yourusername/gems
gempath:
- /home/yourusername/gems
- /usr/lib/ruby/gems/1.8

7. Verify the environment is changed.
$ gem environment
Rubygems Environment:
- VERSION: 0.8.10 (0.8.10)
- INSTALLATION DIRECTORY: /home/yourusername/gems
- GEM PATH:
- /home/yourusername/gems
- /usr/lib/ruby/gems/1.8
- REMOTE SOURCES:
- http://gems.rubyforge.org

8. Install a gem
$ gem install RedCloth
Attempting local installation of 'RedCloth'
Local gem file not found: RedCloth*.gem
Attempting remote installation of 'RedCloth'
Successfully installed RedCloth-3.0.4


9. Add the GEM_PATH to your Rails envorinments.rb file. Do this on each of your apps that will use the local gems. This will tell Rails where to find your gems. For this example, my rails apps are in the RailsApps directory and I'm modifying the app1 configuration.

You will add the ENV line into the environment.rb file. A good place to put it would be at the top of the file, so you remember you added it.

$ vi ~/RailsApps/app1/config/environment.rb
ENV['GEM_PATH'] = '/home/yourusername/gems:/usr/lib/ruby/gems/1.8'

11. Add to your shell environment. This is assuming you are using bash. The .bash_profile will be read next time you login and do this automatically for you.

$ vi .bash_profile
export GEM_PATH=/home/yourusername/gems:/usr/lib/ruby/gems/1.8
export GEM_HOME=/home/yourusername/gems

Then from the command line

$ export GEM_PATH=/home/yourusername/gems:/usr/lib/ruby/gems/1.8
$ export GEM_HOME=/home/yourusername/gems

Verify it
$ echo $GEM_PATH
$ echo $GEM_HOME

12. Run irb to test. You'll see require_gem 'RedCloth' came back as true and 'NotARealGem' threw an error.

$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require_gem 'RedCloth'
=> true
irb(main):003:0> puts RedCloth.new("h1. Header 1\n\nparagraph\n\n").to_html
<h1>Header 1</h1>


<p>paragraph</p>
=> nil
irb(main):004:0> require_gem 'NotARealGem'
Gem::LoadError: Could not find RubyGem NotARealGem (> 0.0.0)

from /usr/lib/site_ruby/1.8/rubygems.rb:194:in `report_activate_error'
from /usr/lib/site_ruby/1.8/rubygems.rb:136:in `activate'
from /usr/lib/site_ruby/1.8/rubygems.rb:37:in `require_gem_with_options'
from /usr/lib/site_ruby/1.8/rubygems.rb:31:in `require_gem'
from (irb):4

13. Now test it out in your app too to make sure that Rails picked up that ENV setting.


**NOTE: I'm new to Ruby, Rails and Site5, so perhaps some experts can chime in and let us know of any easier ways.

Hope that helps someone.
  #2  
Old August 16th, 2006, 12:41 AM
ZackGilbert ZackGilbert is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Apr 2006
Posts: 14
Perfect tutorial! Perfect timing as well. Thanks so much!
  #3  
Old August 25th, 2006, 05:13 PM
johnf johnf is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Apr 2006
Posts: 2
Thanks. Great tutorial.

One question. I did this mainly so that I could attempt to try to use mongrel. I installed it as a gem, but it's not recognized from the command line. Any ideas?
  #4  
Old August 29th, 2006, 10:47 PM
ThinkCup ThinkCup is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jun 2006
Location: Houston, TX
Posts: 3
Send a message via AIM to ThinkCup
Shipping Gem

Hi,

I followed the tutorials; however, for some reason the gem works on command line but not in my rails app. I setup the environments file correctly as well.

Here is the error in my production log:
Code:
MissingSourceFile (no such file to load -- shipping):
    /usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'
    /usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
    /app/controllers/store_controller.rb:2
    /usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:65:in `require_or_load'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:30:in `depend_on'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:85:in `require_dependency'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:285:in `attempt_load'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:281:in `attempt_load'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:237:in `traverse_to_controller'
    generated/routing/recognition.rb:7:in `recognize_path'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:511:in `recognize!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:150:in `process_request'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:54:in `process!'
    /usr/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:600:in `each_cgi'
    /usr/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:597:in `each_cgi'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in `process!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:23:in `process!'
    dispatch.fcgi:24
Any help is appreciated!
  #5  
Old August 30th, 2006, 12:54 AM
dusty.doris dusty.doris is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Aug 2006
Location: Cincinnati, OH
Posts: 3
To the question about not being able to run mongrel from the command-line.

-the gem will be installed in the bin directory inside your local gem repository. Either add that to your path or give the full path to it.
eg: ~/gems/bin/mongrel_rails


To the question about it working on the command line, but not in the rails app.

-What made it work for me was setting the GEM_PATH in the environment.rb file. Make sure to put the path to both your usergems and to the real gems. I'd first double-check that and make sure its setup correctly. Also, make sure you add that to each rails application that you install that will use shipping.

-How did you include the gem into your program? Did you use require_gem 'shipping'?

Last edited by dusty.doris; August 30th, 2006 at 12:55 AM. Reason: typo
  #6  
Old August 30th, 2006, 01:20 AM
ThinkCup ThinkCup is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jun 2006
Location: Houston, TX
Posts: 3
Send a message via AIM to ThinkCup
Thanks dusty.doris

Quote:
Originally Posted by dusty.doris;76851;
-How did you include the gem into your program? Did you use require_gem 'shipping'?
Thank you very much! I was using require 'shipping' not require_gem 'shipping'.

I used require 'shipping' on my local machine and works I guess that's why I was confused. That simple _gem makes a world of difference.

Thanks again!
Scottie
  #7  
Old September 7th, 2006, 08:29 PM
jcblitz jcblitz is offline
Site5 Forum Regular
Between 30 and 100 posts... been around the block a few times.
 
Join Date: Jul 2006
Posts: 41
I set my .gemrc as follows via textmate and uploaded it

Code:
gemhome: /home/wtfhappe/gems
gempath:
- /home/wtfhappe/gems
- /usr/lib/ruby/gems/1.8
Code:
-bash-3.00$ gem environment
/usr/lib/site_ruby/1.8/rubygems.rb:194:in `report_activate_error': Could not find RubyGem sources (> 0.0.0) (Gem::LoadError)
        from /usr/lib/site_ruby/1.8/rubygems.rb:136:in `activate'
        from /usr/lib/site_ruby/1.8/rubygems.rb:37:in `require_gem_with_options'        from /usr/lib/site_ruby/1.8/rubygems.rb:31:in `require_gem'
        from /usr/lib/site_ruby/1.8/rubygems/remote_installer.rb:403:in `sources'
        from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:897:in `execute'
        from /usr/lib/site_ruby/1.8/rubygems/command.rb:49:in `invoke'
        from /usr/lib/site_ruby/1.8/rubygems/cmd_manager.rb:92:in `process_args'        from /usr/lib/site_ruby/1.8/rubygems/cmd_manager.rb:65:in `run'
        from /usr/lib/site_ruby/1.8/rubygems/gem_runner.rb:9:in `run'
        from /usr/bin/gem:17
-bash-3.00$
any ideas?
  #8  
Old September 12th, 2006, 09:58 PM
kbrock kbrock is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Aug 2005
Posts: 20
extra require

1. Using rmagick was giving me some issues.

Turns out I needed to do both:

require_gem 'rmagick'
require 'rnagick'

got the info from http://quirks.exposured.com/ruby/mod...ruby-on-rails/

2. I also had issues when I either started the server before I set the environment.rb or maybe it was the .bashrc - either way. restarting sure fixed things.

So you may want to check your bashrc and your environment.rb file
  #9  
Old October 14th, 2006, 06:20 PM
iamjohnellis iamjohnellis is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Oct 2006
Posts: 1
Maybe I'm retarded, but this is what I get when I try to install gems:
Code:
-jailshell-3.00$ gem install rmagick
Attempting local installation of 'rmagick'
Local gem file not found: rmagick*.gem
Attempting remote installation of 'rmagick'
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /home/iamjohnellis
I'm new. Point me in the right direction, because I'll bet it's something dumb.
  #10  
Old October 17th, 2006, 08:45 PM
kbrock kbrock is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Aug 2005
Posts: 20
Hello and welcome to Site 5

I think this is because you haven't yet created the gems directory in your home

Also, do an echo $GEM_HOME to ensure that it reads /home/iamjohnellis/gems
  #11  
Old October 26th, 2006, 05:41 PM
mrbiotech mrbiotech is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Sep 2006
Posts: 1
Thanks for this great tutorial! Its so nice to see that so many of my questions are already answered here, and answered in such a detailed format.

Worked like a charm for me.
  #12  
Old December 12th, 2006, 12:28 AM
aficionado aficionado is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Oct 2006
Posts: 9
Thumbs up Thank you!

Exactly what I needed, thanks a lot!
  #13  
Old December 19th, 2006, 02:26 AM
onereallybig onereallybig is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Dec 2006
Posts: 6
Worked for me

thanks for the nicely detailed tutorial! Works great
  #14  
Old December 21st, 2006, 04:41 PM
mr_jbuck mr_jbuck is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Dec 2006
Posts: 4
Require_gem not working

Great Tutorial. I installed my gems. (I am using salted login generator and localization) I can seem them, but I don't think my application is using them.

I did the irb and typed require_gem 'insert gems here' and also changed my environment and added
Code:
ENV['GEM_PATH'] = '/home/jasonbuc/gems:/usr/lib/ruby/gems/1.8'
.

Do I need to add require_gem '(gems name)' somewhere else?

Thanks
  #15  
Old December 21st, 2006, 09:51 PM
aficionado aficionado is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Oct 2006
Posts: 9
Did you restart FastCGI?

You will have to restart FastCGI after you change environment.rb: `touch public/dispatch.fcgi`
  #16  
Old January 10th, 2007, 07:51 PM
rteuscher rteuscher is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jan 2007
Posts: 1
not sure if this is a problem, but i didn't get the generated errors for NOTAREALGEM

why didn't i get the error suppossedly generated when typing NotARealGem. it didn't return anything?

code:

-jailshell-3.00$ echo $GEM_PATH
/home/flipping/gems:/usr/lib/ruby/gems/1.8
-jailshell-3.00$ echo $GEM_HOME
/home/flipping/gems
-jailshell-3.00$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require_gem 'RedCloth'
=> true
irb(main):003:0> puts RedCloth.new("h1. Header 1\n\nparagraph\n\n").to_html
<h1>Header 1</h1>


<p>paragraph</p>
=> nil
irb(main):004:0> <h1>Header 1</h1>
irb(main):005:0/ require_gem 'NotARealGem'
  #17  
Old January 10th, 2007, 07:59 PM
aficionado aficionado is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Oct 2006
Posts: 9
Quote:
irb(main):004:0> <h1>Header 1</h1>
irb(main):005:0/ require_gem 'NotARealGem'
Looks like you were continuing the last command "<h1>Header 1</h1>" when you did that (note the "/" instead of ">" at the end of the prompt). Ctrl-C once to start a new command then try it, you will get similar results. Below is what I get when I run that command.

Quote:
irb(main):006:0> require_gem "NotRealGem"
Gem::LoadError: Could not find RubyGem NotRealGem (> 0.0.0)

from /usr/lib/site_ruby/1.8/rubygems.rb:194:in `report_activate_error'
from /usr/lib/site_ruby/1.8/rubygems.rb:136:in `activate'
from /usr/lib/site_ruby/1.8/rubygems.rb:37:in `require_gem_with_options'
from /usr/lib/site_ruby/1.8/rubygems.rb:31:in `require_gem'
from (irb):6
from /usr/lib/site_ruby/1.8/rubygems/specification.rb:383
  #18  
Old January 20th, 2007, 12:43 AM
kdugan's Avatar
kdugan kdugan is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: May 2005
Posts: 3
Send a message via Skype™ to kdugan
I have followed this step by step, and my environment looks like this:

Code:
Rubygems Environment:
  - VERSION: 0.8.10 (0.8.10)
  - INSTALLATION DIRECTORY: /home/mylogin/gems
  - GEM PATH:
     - /home/mylogin/gems
     - /usr/lib/ruby/gems/1.8
  - REMOTE SOURCES:
     - http://gems.rubyforge.org
But when I try to install a gem this is what happens:

Code:
-jailshell-3.00$ gem install radiant --include-dependencies
Attempting local installation of 'radiant'
Local gem file not found: radiant*.gem
Attempting remote installation of 'radiant'
ERROR:  While executing gem ... (OpenURI::HTTPError)
    404 Not Found
Can someone tell me why this is? I'm baffled

-----
Update: I spoke with customer service and this was an issue with the gem mirror not having the gems I was looking for. Now things work as they should. Good times!

Last edited by kdugan; January 21st, 2007 at 01:30 PM. Reason: Found solution
  #19  
Old January 24th, 2007, 02:45 AM
evansagge evansagge is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Dec 2006
Posts: 4
Nice tutorial.

I got my Rails app running under the new Rails 1.2.1 gem that I installed on my account. I was able to deploy it gracefully.

But when I came to running `cap migrate`, I got this problem:

Code:
$ cap migrate
  * executing task migrate
  * executing "cd /home/username/apps/babyland/current && rake RAILS_ENV=production  db:migrate"
    servers: ["mydomain.com"]
    [mydomain.com] executing command
 ** [out :: mydomain.com] (in /home/username/apps/babyland/releases/20070124063356)
 ** [out :: mydomain.com] Cannot find gem for Rails ~>1.2.1.0:
 ** [out :: mydomain.com] Install the missing gem with 'gem install -v=1.2.1 rails', or
 ** [out :: mydomain.com] change environment.rb to define RAILS_GEM_VERSION with your desired version.
 ** [out :: mydomain.com] 
 ** [out :: mydomain.com] rake aborted!
 ** [out :: mydomain.com] exit
 ** [out :: mydomain.com] /home/username/apps/babyland/releases/20070124063356/Rakefile:4
 ** [out :: mydomain.com] (See full trace by running task with --trace)
    command finished
command "cd /home/username/apps/babyland/current && rake RAILS_ENV=production  db:migrate" failed on mydomain.com
Does anyone have a solution to this? Thanks for the help.
  #20  
Old January 25th, 2007, 01:56 AM
theli theli is offline
New Site5 Forum Member
Error: User doesn't post enough! ... less than 30 posts
 
Join Date: Jul 2006
Posts: 3
evansagge, I'm running into the exact same problem. it would seem when capistrano logs in via SSH to execute a command, it opens a non-login shell. As such it does not load .bash_profile. It should load .bashrc but I believe that site5 has disabled it.

I'm currently looking into a way to add this in a similar manner to environment.rb
Closed Thread

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HOWTO Install Django on Site5 Topdeck How To: Tutorials 77 February 27th, 2008 11:45 AM
Howto: Subdomains inside Rails App Jomdom Ruby 11 December 16th, 2007 05:22 PM
How to check the installed Gems? hybernate Ruby 1 August 1st, 2006 10:00 AM
Ruby Gems ChrisGoodrich Ruby 3 April 21st, 2006 06:28 AM
HOWTO: transfer/backup your Wordpress install Carla Hufstedler How To: Tutorials 1 April 1st, 2006 08:40 PM


All times are GMT -4. The time now is 10:27 PM.

Feeds:   RSS  |   RSS2  |   XML
Forum home
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
  
Copyright © 2009 Site5 LLC