![]() |
![]() |
|
|
|||||||
| Ruby Discussion of Ruby and all related code, and its usage and development, both on Site5 servers and elsewhere |
|
|
Thread Tools |
Rating: |
Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
Perfect tutorial! Perfect timing as well. Thanks so much!
|
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|
#5
|
|||
|
|||
|
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
|
|||
|
|||
|
Thanks dusty.doris
Quote:
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
|
|||
|
|||
|
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$
|
|
#8
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|
#10
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Exactly what I needed, thanks a lot!
|
|
#13
|
|||
|
|||
|
Worked for me
thanks for the nicely detailed tutorial! Works great
|
|
#14
|
|||
|
|||
|
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
|
|||
|
|||
|
Did you restart FastCGI?
You will have to restart FastCGI after you change environment.rb: `touch public/dispatch.fcgi` |
|
#16
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
Quote:
|
|
#18
|
||||
|
||||
|
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
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
![]() ----- 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
|
|||
|
|||
|
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
|
|
#20
|
|||
|
|||
|
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 |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
|
|
||||
| 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 |