Ruby, how to set GEM_PATH, for Rails project on hostmonster?

11,063

Well apparently the gems I was trying to use were not installed on my server. I thought I had installed them myself when I ran gem install sass. However this didn't work properly because Hostmonster had to give me permission to install gems.

I found that out here...

https://my.hostmonster.com/cgi/help/221

As for the path I had to do the following..

home = File.expand_path("/home/#{ENV['MYCPANELUSERNAME']}")
ENV['GEM_PATH'] = "#{home}/ruby/gems:/usr/lib64/ruby/gems/1.8"

So basically for the path all I had to do was change 'USER' to my cpanel username.

Also note this only works if my .htaccess is set to "production" instead of "development".

Thread on production vs development

And in addition to this I also had a problem with my .htaccess file.

So I had to edit my .htacess file using vi editor. (might be different for other people)

Make sure .htaccess had this content in it

  • Options -MultiViews
  • PassengerResolveSymlinksInDocumentRoot on
  • RailsEnv production RackBaseURI / SetEnv GEM_HOME
  • /home1/examplec/ruby/gems
Share:
11,063
khollenbeck
Author by

khollenbeck

Various levels of experience with: JAVASCRIPT JavaScript Angular/Typescript Node jQuery Dabbled with React lodash mustache JS Tooling/Testing Angular Cli Grunt Cli Webpack NPM Karma Protractor HTML and CSS HTML Jade CSS SASS Java Java Ant/Maven Database MYSQL Mongo Source Control GIT SVN

Updated on June 04, 2022

Comments

  • khollenbeck
    khollenbeck almost 2 years

    I am new to ruby and having a hard time setting up my gems. Could someone please help me understand how this path works in environment.rb

    Some Background Info:

    I have my rails app installed on hostmonster and I am trying to run SASS using SHELL. I have no local copy of my app. When I run the SASS command I get -bash: sass: command not found. Which leads me to believe my gem path is wrong. The problem though is that i don't really understand how the path works.

    I am confused about this line in particular...

    home = File.expand_path("/home/#{ENV['USER']}")    
    ENV['GEM_PATH'] = "#{home}/ruby/gems:/usr/lib64/ruby/gems/1.8"
    

    NOTE: This is the default path which was set when I installed my Rails app from the Cpanel.

    Some things I don't understand...

    1. What is the purpose of the semicolon?
    2. For #{home} , am I suppose to replace that with my home directory?
    3. Where would usr/lib64 come from? I don't see that directory. I am assuming I have to create it.

    ALSO: This is what hostmonster tells me to do (which I have done already)...

    Using File Manager in your cPanel make a copy of the .bashrc file in your root directory, name it .bashrc.bak. Now edit the .bashrc file and add the following to the end of the file:

    • export GEM_HOME=$HOME/ruby/gems
    • export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8
    • export GEM_CACHE=$GEM_HOME/cache
    • export PATH=$PATH:$HOME/ruby/gems/bin

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

    I apologize if this is a "noobish" questions, I have never used Ruby so I am still learning how it all works. I have ruby, rails, and sass all installed. I can run my project in the browser. i just can't get my gems to work. Thanks in advance.