Web Development 的學習之旅

2007/06/13

Rails 讀取 Gem 需要的設定

問題: 在安裝 RedCloth 後, rails 仍無法使用.

即使執行 xxx@xxx.xxx [~/path]# gem install GEM_NAME成功後, rails 仍然無法使用, 解決的方式是在 ./config/environment.rb 內增加下面設定, 告訴 rails 那裡可以找到 gems:

ENV['GEM_PATH'] = '/home/[account_name]/.gems:/usr/lib/ruby/gems/1.8'


下面 HM 裡的文章可以參考之, 不過目前我還沒有更改 .bashrc 檔案, 也沒有 install local gem directory, 只改了 environment.rb 後 rails 就讀得到了.

update: 後來似乎還是有問題, 最後我還是改了 .bashrc 檔案

==========

How do I install my own Gems?

Problem:
The easiest and fastest way to install Ruby gems is to install them in your local directory, you will need shell access. To install your own gems use the following steps:

Solution:
1) Using File Manager in your cPanel make a copy of the .bashrc file in your root directory, name it .bashrc.bak.
2) Now edit the .bashrc file and add the following to the end of the file:
export PATH="$PATH:$HOME/packages/bin:$HOME/.gems/bin"
export GEM_HOME="$HOME/.gems"
export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"
export GEM_CACHE="$GEM_HOME/cache"


3) Using your favorite SSH client connect to your site.

4) at the prompt type:

xxx@xxx.xxx [~/path]# cp /usr/lib/ruby/gems/1.8/cache/sources-0.0.1.gem ./
xxx@xxx.xxx [~/path]# gem install sources-0.0.1.gem
xxx@xxx.xxx [~/path]# gem update -y

This will update rails to the latest version and install it to your local gem directory.


5) When using a rails application, make sure you add the following to your ./config/environment.rb:
ENV['GEM_PATH'] = '/path/to/your/home/.gems:/usr/lib/ruby/gems/1.8'

沒有留言: